jQuery事件监听器,用于在& lt; td& gt;中更改文本的时间细胞? [英] jQuery event listener for when text has changed in a <td> cell?

查看:162
本文介绍了jQuery事件监听器,用于在& lt; td& gt;中更改文本的时间细胞?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery中是否有任何方法可以将侦听器附加到<td>单元格,以便当单元格中的文本发生更改时(由JavaScript而不是用户更改),便会触发事件?

Is there any way in jQuery to attach a listener to a <td> cell so that when the text inside the cell has changed (by JavaScript, not the user), the event is triggered?

推荐答案

扩展

To extend mway's answer, here is some code.

var td = $('#my-table tr td:eq(1)');
var tdHtml = td.html();
setInterval(function() {

    if (td.html() !== tdHtml) {
         // it has changed
         tdHtml = td.html();
    } 

}, 500);

...还有他的第二个建议.

... and for his second suggestion.

function updateTd(html) {
     $('#my-table tr td:eq(1)').html(html);

     // additional code
}

您还可以将DOMSubtreeModified事件绑定到该元素,但是对浏览器的支持并不是最好的.

You could also bind the DOMSubtreeModified event to the element, but browser support isn't the best.

这篇关于jQuery事件监听器,用于在&amp; lt; td&amp; gt;中更改文本的时间细胞?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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