javascript - 内联函数按 id 调用自动元素
问题描述
我有一个好奇想问,为什么通过在onclick函数中直接插入id,比如调用表格呢?
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')
虽然不推荐这样做
推荐阅读
- python - 如何清除用户输入?
- android - Android 通知:通知和数据有效负载有什么不同
- android - 如何为抽屉菜单项创建带圆角的波纹?
- reactjs - Pass a ref to a component
- java - Passing a varable from a JFrame to another
- java - 设置多项目/复合构建时的 Gradle 错误
- angular - RxJs - 取消点击上的所有子事件(导航到另一个选项卡)
- gradle - Why is Gradle Plugin not collecting build scan in Jenkins file
- amazon-emr - Samza 1.1.0 - run-app.sh 在部署 hello samza 期间不起作用
- intellij-idea - 尽管连接了库,但无法将 fontawesome 库加载到 Intellij Idea