Javascript 如何使用jquery在div元素的href链接中查找单词
有一个div元素始终包含a href元素中的一个数组字。根据单词的不同,我需要将网页重定向到不同的页面。我不确定我错过了什么Javascript 如何使用jquery在div元素的href链接中查找单词,javascript,jquery,html,loops,switch-statement,Javascript,Jquery,Html,Loops,Switch Statement,有一个div元素始终包含a href元素中的一个数组字。根据单词的不同,我需要将网页重定向到不同的页面。我不确定我错过了什么 if($('.container-fluid:contains(“它看起来像这样”)).length>0 | |($('.container-fluid:contains(“您访问过”)).length>0)){ var uTest=[“Saggitarius”、“Quentin”、“Cinthia”、“Maleria”、“Pete”、“Library”、“wizard
if($('.container-fluid:contains(“它看起来像这样”)).length>0 | |($('.container-fluid:contains(“您访问过”)).length>0)){
var uTest=[“Saggitarius”、“Quentin”、“Cinthia”、“Maleria”、“Pete”、“Library”、“wizard”];
var aTest=uTest.长度;
var i=0;
对于(i;i0){
var mTest=uTest[i];
if(mTest!=null | |未定义){
开关(mTest){
“Saggitarius”案:
window.location.href=https://subeta.net/quests.php/saggitarius';
打破
“昆廷”案:
window.location.href='…';
打破
“Cinthia”病例:
window.location.href='…';
打破
“Maleria”案:
window.location.href='…';
打破
案例“Pete”:
警惕(“皮特”);
打破
案例“图书馆”:
window.location.href='…';
打破
案例“向导”:
window.location.href='…';
打破
“莫里”案:
window.location.href='…';
打破
}
}否则{
警惕(“完成”);
}
}
}
}这是一种非常糟糕的选择链接的方法。例如,你现在依赖于
Sagittarius
的拼写错误(它有一个g
——我碰巧是一个Sagittarius)。最好将链接放到页面中(作为数据属性?:)此处出现分析错误$(.container-fluid:contains(uTest[i]))
。这应该是$('.container fluid:contains(“+uTest[i]+”)”)
谢谢,使用您的修复程序+var i=0解决了错误。我在tampermonkey上运行这个,这就是为什么Saggitarius是网页的实际链接,并且它从不改变。
if ($('.container-fluid:contains("It looks something like this")').length > 0 || ($('.container-fluid:contains("Have you visited")').length > 0)) {
var uTest = ["Saggitarius", "Quentin", "Cinthia", "Maleria", "Pete", "Library", "wizard"];
var aTest = uTest.length;
var i = 0;
for (i; i < aTest; i++) {
if ($('.container-fluid:contains("'+uTest[i]+'")').length > 0) {
var mTest = uTest[i];
if (mTest != null || undefined) {
switch (mTest) {
case "Saggitarius":
window.location.href = 'https://subeta.net/quests.php/saggitarius';
break;
case "Quentin":
window.location.href = '...';
break;
case "Cinthia":
window.location.href = '...';
break;
case "Maleria":
window.location.href = '...';
break;
case "Pete":
alert("Pete");
break;
case "Library":
window.location.href = '...';
break;
case "wizard":
window.location.href = '...';
break;
case "Mori":
window.location.href = '...';
break;
}
} else {
alert("done");
}
}
}