jquery 中用于变量更改的事件监听器
我想在浏览网站时跟踪变量。我怎样才能使用 jQuery 输出这个值,而不必担心追踪它可能受到影响的地方并更新它。
var num = 1;
$(#trackvariable).text(num)
我希望上面的内容能够像以前一样不断执行。我不一定想在计时器上执行它。有什么办法可以做到这一点吗?
I want to track a variable as I navigate around my site. How can I use jQuery to output this value without having to worry about tracking down wherever it might be affected and having it update.
var num = 1;
$(#trackvariable).text(num)
I want the above to execute constantly as it were.. I don't necessarily want to do it on a timer. Is there any way to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果你想监听文本节点上的变化,你可以这样做:
If you want to listen to changes on a textnode, you can do something like this:
这仅适用于 Firefox(也可能适用于 Safari 中的 Chrome):
https:// developer.mozilla.org/en/JavaScript/Guide/Working_with_Objects#Defining_Getters_and_Setters
This will only work in Firefox (and probably Chrome in Safari also):
https://developer.mozilla.org/en/JavaScript/Guide/Working_with_Objects#Defining_Getters_and_Setters
我突然想到,更改变量的函数应该在其末尾调用某种更新函数吗?只是一个想法。我认为即使您设置了某种自定义事件,它仍然需要在每个函数中手动触发。
Off the top of my head I would say that the functions changing the variable should just call some sort of update function at the end of them? just an idea. I think even if you set up some kind of custom event it would still have to manually triggered in each function.