jQuery事件:检测对div的html/text的更改 [英] jQuery Event : Detect changes to the html/text of a div

查看:99
本文介绍了jQuery事件:检测对div的html/text的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div,其内容一直在变化,例如ajax requestsjquery functionsblur等.

I have a div which has its content changing all the time , be it ajax requests, jquery functions, blur etc etc.

有什么方法可以随时检测div上的任何更改吗?

Is there a way I can detect any changes on my div at any point in time ?

我不想使用已检查的任何间隔或默认值.

I dont want to use any intervals or default value checked.

类似的事情

$('mydiv').contentchanged() {
 alert('changed')
}

推荐答案

如果您不想使用计时器并检查innerHTML,则可以尝试此事件

If you don't want use timer and check innerHTML you can try this event

$('mydiv').bind("DOMSubtreeModified",function(){
  alert('changed');
});

更多详细信息和浏览器支持数据为此处.

More details and browser support datas are Here.

注意::在较新的jQuery版本中,bind()已被弃用,因此应改为使用on():

Attention : in newer jQuery versions bind() is deprecated, so you should use on() instead:

$("body").on('DOMSubtreeModified', "mydiv", function() {
    alert('changed');
});

这篇关于jQuery事件:检测对div的html/text的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆