如何监视jQuery中body'data'属性的变化? [英] How to monitor when the body 'data' attribute changes in jQuery?

查看:244
本文介绍了如何监视jQuery中body'data'属性的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的body标签中的数据段属性由滑块更改。我需要在更改时触发基于此值的函数。

I have data-segment attribute in my body tag that is changed by a slider. I need to trigger a function based on the value of this, when it is changed.

我不确定如何在这种情况下附加事件监听器? / p>

I'm not sure how to attach an event listener in this case though?

推荐答案

`当DOM节点属性发生变化时,没有可靠的跨浏览器方式来接收事件。有些浏览器支持DOM变异事件,但你不应该依赖它们,而你可能会谷歌那句话来了解该技术的命运多变的历史。

`There is no reliable cross-browser way to receive an event when a DOM node attribute is changed. Some browsers support "DOM mutation events", but you shouldn't rely on them, and you may Google that phrase to learn about the ill-fated history of that technology.

如果滑块控件没有触发自定义事件(我认为大多数现代事件都会这样做),那么最好的办法是设置一个 setInterval()方法来轮询值。

If the slider control does not fire a custom event (I would think most modern ones do), then your best bet is to set up a setInterval() method to poll the value.

这篇关于如何监视jQuery中body'data'属性的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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