gpt4 book ai didi

javascript - 内联函数通过 id 调用自动元素

转载 作者:行者123 更新时间:2023-12-04 14:59:43 24 4
gpt4 key购买 nike

好奇问一下,为什么通过在onclick函数中直接插入id,比如table被召回?

function See(table){
console.log(table); // how system catch automatic the element?
}
<table id='iamtable' border="1">
<thead>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th></th>
</thead>
<tbody>
<tr>
<td>Value</td>
<td>Value</td>
<td>Value</td>
<td><button onclick='See(iamtable);'>press me</button>
</tr>
</tbody>
</table>

最佳答案

为元素设置一个 id,在 window 对象中创建一个引用。您可以使用

window.theid // or short theid
代替
document.getElementById('theid')
虽然不推荐这样做

关于javascript - 内联函数通过 id 调用自动元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67211561/

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