使用jQuery检测元素内容更改 [英] Detect element content changes with jQuery

查看:104
本文介绍了使用jQuery检测元素内容更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

change() function可以检测表单元素的变化,但是有没有办法检测DOM元素的内容何时被更改?

change() function works and detects changes on form elements, but is there a way of detecting when a DOM element's content was changed?

这不起作用,除非 #content 是一个表单元素

This does not work, unless #content is a form element

$("#content").change( function(){
    // do something
});

我希望在执行以下操作时触发:

I want this to trigger when doing something like:

$("#content").html('something');

另外 html() append()函数没有回调。

任何建议?

推荐答案

这些是突变事件

我没有在jQuery中使用突变事件API,但是粗略搜索导致我在GitHub上此项目。我不知道项目的成熟度。

I have not used mutation event APIs in jQuery, but a cursory search led me to this project on GitHub. I am unaware of the project's maturity.

这篇关于使用jQuery检测元素内容更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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