在< td>中更改文本时的jQuery事件侦听器细胞? [英] jQuery event listener for when text has changed in a <td> cell?

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

问题描述

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

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

推荐答案

扩展 mway的回答,这是一些代码。

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.

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

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