JQuery的不能在$执行(文件).change() [英] JQuery does not execute on $(document).change()
本文介绍了JQuery的不能在$执行(文件).change()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在页面/文件已经改变了一些jQuery执行 - 在这种情况下,当显示与特定CSS类的div
I need to make some JQuery execute when the page/document has changed - in this case, when a div with a specific CSS class is displayed.
我有以下的JQuery code:
I have the following JQuery code:
<script>
$(document).change(function () {
if ($('.validation_errors').length) {
alert("test");
}
}
</script>
然而,它不执行并显示警报。我失去了一些东西在这里?
However, it does not execute and display the alert. Am I missing something here?
推荐答案
更改仅用于输入,文本区域或选择元素。相反,你需要绑定到 DOMSubtreeModified
突变事件的函数:
Change is only for input, textarea or select elements. Instead you need to bind a function to the DOMSubtreeModified
mutation event:
$(document).bind('DOMSubtreeModified', function () {
if ($('.validation_errors').length) {
alert("test");
}
});
编辑:如果你的目标浏览器支持的话,你应该使用 MutationObserver 的,而不是
这篇关于JQuery的不能在$执行(文件).change()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文