如何监视人体数据jQuery中的属性更改? [英] How to monitor when the body 'data' attribute changes in jQuery?

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

问题描述

我的body标签中有data-segment属性,该属性由滑块更改.更改时,我需要基于此值触发一个函数.

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.

在这种情况下,我不确定如何附加事件侦听器吗?

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

推荐答案

`当DOM节点属性更改时,没有可靠的跨浏览器方式来接收事件.有些浏览器支持"DOM突变事件",但您不应该依赖它们,您可以使用Google这个短语来了解该技术的不幸历史.

`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中的属性更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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