写上注释 var url = documentgetElementByIdinput-linkvaluetrim; var pattern = ^a-zA-Z0-9_-+a-zA-Z0-9_-++a-zA-Z0-9_-^=&~+#a-zA-Z0-9_-^=&~+#$; var match = urlmatchpattern; if match !== null
// 获取输入框中的链接 var url = document.getElementById("input-link").value.trim();
// 定义链接格式的正则表达式 var pattern = /^[a-zA-Z0-9_-]+(.[a-zA-Z0-9_-]+)+([a-zA-Z0-9_-.,@?^=%&:/~+#][a-zA-Z0-9_-@?^=%&:/~+#])$/;
// 使用正则表达式匹配链接 var match = url.match(pattern);
// 如果链接格式正确 if (match !== null) { // 构建新的链接 var newUrl = "ks.php?url=" + match[0]; // 跳转到新链接 location.href = newUrl; // 设置cookie setCookie("attempts", ++attempts, expires); } else { // 如果链接格式不正确,弹出提示框 alert("输入的链接格式不正确,请重新输入。"); }
原文地址: http://www.cveoy.top/t/topic/0yW 著作权归作者所有。请勿转载和采集!