我有那个脚本:
// ==UserScript==
// @name example
// @include http://xxx*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
// ==/UserScript==
var findElem = function(elems, text) {
for (var i = 0; i < elems.length; i++) {
if (elems[i].textContent == text) {
return elems[i];
} else {
var result = findElem(elems[i].children, text);
if (result != undefined) {
return result;
}
}
}
return;
}
switch (document.getElementById('my_id').value) {
case "1":
findElem(document.documentElement.children, "blabla1").click();
break;
case "2":
findElem(document.documentElement.children, "blabla2").click();
break;
case "3":
findElem(document.documentElement.children, "blabla3").click();
break;
case "4":
findElem(document.documentElement.children, "blabla4").click();
break;
default:
break;
}
它工作正常,但它只适用于主页加载。我想在通过 ajax 更改页面时运行它。我怎样才能做到这一点?
也请举例说明你的答案。我是新手。我不知道如何在你的答案中使用东西。