gpt4 book ai didi

javascript - 如何将 handsontable 数据传输到同一页面上的不同 JavaScript?

转载 作者:行者123 更新时间:2023-11-29 14:56:54 24 4
gpt4 key购买 nike

这是 jsfiddle 的链接handsontable 的代码。按下按钮时,数据集将转到控制台。我的网页上有两段不同的 JavaScript 代码。其中之一包含 handsontable我如何将数据传输(转储)到属于不同脚本片段(而不是控制台)的数组?有没有什么方法可以创建一个static数组所有脚本(如 Java)?这是方案:

<div id="mytable" class="handsontable"> </div>
<script>
// Here the user inserts the data to the handsontable. As she presses the button, data should go to the second piece of script.
</script>

...

<div id="target" class=""> </div>
<script>
//the target array is here, and it needs to be filled with the data from the above piece of script as the button is pressed.
</script>

最佳答案

有很多方法可以做到,例如:

1.) 创建全局变量来保存数据

<div id="mytable" class="handsontable"> </div>

<script>
// set data
window.data = getCarData();

$("#example1").handsontable({
data: window.data
});
</script>

<div id="target" class="class"> </div>

<script>
//get data
var array = window.data;
</script>

2.) 如果您使用 jQuery:

// you can bind data to element
$('table').data('key', 'value');

// and then get it
$('table').data('key');

关于javascript - 如何将 handsontable 数据传输到同一页面上的不同 JavaScript?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16323744/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com