gpt4 book ai didi

javascript - 现代浏览器不支持"DOMAttrModified"事件?

转载 作者:行者123 更新时间:2023-12-02 16:07:20 24 4
gpt4 key购买 nike

以下是代码 (Jsfiddle demo):

<a href="#">Click me!</a>

<script>
var a = document.body.children[0]

a.onclick = function() {
alert('in onlick')
this.setAttribute('href', 'lala')
alert('out onclick')
return false
}

function onpropchange() {
alert('onpropchange')
}

if (a.addEventListener) { // FF, Opera
a.addEventListener('DOMAttrModified', onpropchange, false)
}
if (a.attachEvent) { // IE
a.attachEvent('onpropertychange', onpropchange)
}
</script>

<a href>Click me!</a>被点击。 alert('onpropchange')没有执行..(我使用的是 Chrome 43.0)有人对此有什么想法吗?

最佳答案

来自docs of mutation events

This feature has been removed from the Web. Though some browsers may still support it, it is in the process of being dropped. Do not use it in old or new projects. Pages or Web apps using it may break at any time.

使用mutationObserver如果可能的话。

关于javascript - 现代浏览器不支持"DOMAttrModified"事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30588459/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com