3
我有這個代碼在Firefox中完美工作。DOMSubtreeModified不能在鉻
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script type="text/javascript">
function CreateEvent()
{
var x = document.createEvent("MutationEvent");
x.initMutationEvent("DOMSubtreeModified", true, false, null, "", "", "", 0);
document.dispatchEvent(x);
}
$(document).ready(function() {
$('#myDiv')[0].addEventListener('DOMNodeRemoved', function() { console.log('Content removed!'); }, false);
$('#myDiv')[0].addEventListener('DOMSubtreeModified', function() { console.log('DOMSubtreeModified modified!'); }, false);
$('#myDiv')[0].addEventListener('DOMNodeRemovedFromDocument', function() { console.log('DOMNodeRemovedFromDocument !'); }, false);
$('#myDiv')[0].addEventListener('DOMNodeInserted', function() { console.log('DOMNodeInserted !'); }, false);
$('#myBtn').click(function (e) {
$('#myDiv').css({ marginLeft : "300px"});
});
});
</script>
</head>
<body>
<div id="myDiv">Content</div>
<div id="myBtn">
Button
</div>
</body>
</html>
但它不適用於Chrome。我希望每次發生myDiv事件時都會觸發一個事件。 (刪除,css修改,一切)。
任何變通?
看看類似的問題,我問了http://stackoverflow.com/questions/7692730/dom-mutation-event-in-jquery-or-vanilla-javscript。 –
爲什麼你會期望一個CSS修改來觸發你想要處理的事件? –
http://code.google.com/p/chromium/issues/detail?id=59906,http://code.google.com/p/chromium/issues/detail?id=30191 – Dev