当该跨度值更改时,如何触发事件?

编程入门 行业动态 更新时间:2024-10-26 19:28:21
本文介绍了当该跨度值更改时,如何触发事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当当前页面的股票价格发生变化时,我正在尝试获取控制台日志.

I'm trying to get a console log when the price of the current page's stock changes.

页面: www.google/finance?q=NASDAQ%3AGOOG&; ei = yvbRVbHSCcKgmAGyu7CoDA

元素ID:#price-panel> div> span> span

Element ID: #price-panel > div > span > span

尝试1: 失败

$("#price-panel div span span").onchange = function() { console.log('change')}

尝试2: 失败

document.getElementById('price-panel').children[0].children[0].onchange = function() { console.log('change')}

builtwith表示javascript是"google api",与google搜索有歧义,因此并没有太大帮助.

builtwith says the javascript is the "google api" which is ambiguous to google searches so that didn't help much.

该元素更改时,我可以观看什么事件来找出?

What event can I watch to find out when this element is change?

推荐答案

来自 Dom事件尝试收听< span> 中的文本更改,则可以使用 DOMCharacterDataModified .

From Dom Events as your try to listen to text changes in <span> you may be able to use DOMCharacterDataModified.

或者您可以使用 MutationObserver 来捕获变化.

Or you can use MutationObserver to capture the changes.

var span = document.querySelector('#test'); var text = document.createTextNode('tttt'); // This may be deprecated. span.addEventListener('DOMCharacterDataModified', function() { alert('span text changed to: ' + this.innerHTML); }); // You may use MutationObserver instead. var mutateObserver = new MutationObserver(function(records) { console.log(records); }); mutateObserver.observe(span, { childList: true, // capture child add/remove on target element. characterData: true, // capture text changes on target element subtree: true, // capture childs changes too characterDataOldValue: true // keep of prev value }); setTimeout(function() { span.innerHTML ='SSSS'; }, 2000); setTimeout(function() { span.appendChild(text); }, 3000); setTimeout(function() { text.data = '3123'; }, 4000);

<span id="test">This is a span</span>

更多推荐

当该跨度值更改时,如何触发事件?

本文发布于:2023-11-04 01:23:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1556563.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:跨度   事件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!