如何确定何时更改html元素的文本 [英] How to determine when the text of an html element is changed

查看:89
本文介绍了如何确定何时更改html元素的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到这样的错误消息:

I have an error message like this:

<span class="errorMessage">Your input sucks!</span>

,我需要确定何时更改.我使用的验证框架会在出现错误时设置文本,并在完成时将其删除.我希望通过使用jquery监视元素的text属性的更改来利用它.关于如何执行此操作的任何想法?

and I need to determine when it changes. the validation framework I'm using sets the text when there's an error and removes it when it's complete. I'm hoping to tap into that by watching for changes to the text property of the element using jquery. Any idea of how to go about doing this?

谢谢!

推荐答案

处理DOMCharacterDataModified事件将是正确的(并且可能是不涉及轮询的唯一方法).

Handling the DOMCharacterDataModified event would be the proper (and probably the only way that does not involve polling).

但是,IE不支持此事件,并且其他一些浏览器也有一些限制,可能对您没有用: http://www.quirksmode.org/dom/events/#t12

However, IE does not support this event and some other browsers have some limitations which might make it useless for you: http://www.quirksmode.org/dom/events/#t12

因此,最简单的解决方案可能是设置一个间隔计时器,该计时器每隔约250毫秒检查一次元素的内容,然后触发您要执行的任何操作.

So probably the easiest solution will be to setup an interval timer which checks your element's contents every ~250ms and then triggers whatever action you want to execute.

这篇关于如何确定何时更改html元素的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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