简体   繁体   English

从浏览器中的实时表记录数据

[英]Log data from a real-time table in browser

Let's say there's a real-time table on a website (For example a Forex website).假设网站上有一个实时表格(例如外汇网站)。 There would be one table and the cell value changes dynamically.将有一个表格,并且单元格值动态变化。 There wouldn't be any input, it's just like a live update of the cell value.不会有任何输入,就像单元格值的实时更新一样。

I can get to the cell value using this code.我可以使用此代码获取单元格值。 (Tweaking the row and column indices for the data I want) (调整我想要的数据的行和列索引)

document.getElementById('cr1').rows[1].cells.item(2).innerHTML

I want to log the data every time a cell value changes.我想在每次单元格值更改时记录数据。 So, my idea was to write some event listener which gets fired every time the cell value changes and append the new data to an array variable and then to save it whenever I want.因此,我的想法是编写一些事件侦听器,每次单元格值更改时都会触发该事件侦听器,并将新数据 append 写入数组变量,然后随时保存。 So, how can I write a function to automatically store this?那么,我怎样才能写一个 function 来自动存储呢? Like is there a listener available?比如有没有可用的监听器?

I want to do this using the Console provided by Google Chrome.我想使用 Google Chrome 提供的控制台来执行此操作。

Try using DOMSubtreeModified event尝试使用DOMSubtreeModified事件

let arr=[]
document.getElementById('cr1').rows[1].cells[0].addEventListener('DOMSubtreeModified',function(){
     arr.push(document.getElementById('cr1').rows[1].cells[2].innerHTML)
    });

 document.getElementById('tb').rows[1].cells[0].addEventListener('DOMSubtreeModified', function() { console.log("Im changed"); }); document.getElementById('changeData').addEventListener('click', function(e) { document.getElementById('tb').rows[1].cells[0].innerText = "Supercool"; }); document.getElementById('changeDataL').addEventListener('click', function(e) { document.getElementById('tb').rows[1].cells[1].innerText = "Antarctia1"; });
 <table id="tb"> <tr> <th> Name </th> <th> Location </th> </tr> <tr> <td> Superman </td> <td> Antarctica </td> </tr> <tr> <td> John </td> <td> Iceland </td> </tr> </table> <button id="changeData">Change superman</button><button id="changeDataL">Change antarctica</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM