Pau*_*uck 2 html javascript jquery
<span id="one"> one </span>
<span id="two"> two </span>
$("#one").mouseover(function(){
$(this).css('background-color', 'red');
});
$("#two").click(function(){
$(this).css('background-color', 'green');
});
if (any changes on the site) {
alert('changes detected');
}
Run Code Online (Sandbox Code Playgroud)
我如何检测到页面上的任何更改?这可能吗?我想使用函数.live(),但如何使用?
我不想单独检查页面上的每个功能。
您可以使用window.setTimeout(), 捕获主体 ( document.body.innerHTML)的当前 HTML并将其与之前保存的 HTML 进行比较:
var lastBodyHTML = "";
var changes = 0;
function test() {
if (lastBodyHTML == "") {
lastBodyHTML = document.body.innerHTML;
}
if (lastBodyHTML != document.body.innerHTML) {
changes++;
alert("CHANGE #" + changes);
lastBodyHTML = document.body.innerHTML;
}
window.setTimeout(test, 1000);
};
test();
Run Code Online (Sandbox Code Playgroud)
工作示例:http : //jsfiddle.net/d4PMB/7/
| 归档时间: |
|
| 查看次数: |
1555 次 |
| 最近记录: |