我想要一个表格,它的单元格中充满了来自MySQL的数据。
这个表有很多Id,它们有一个Id。
我希望将单元格的id传递给函数,以便编辑其内容:
document.getElementById(IndexedActionButton).innerHTML = '<input type="Button" name = "EditActionButton" id="EditActionButton" onClick="SaveUpdateToActionList("Cell_ID")" value="Edit Action" />';
function SaveUpdateToActionList(Cell) {
alert(Cell);
document.getElementById(Cell).innerHTML = 'Here';
}当我显示alert(Cell);时,我看到它发送文本"Cell_ID",而我想在那里看到数据ActionButton386。
任何帮助都很感激。
发布于 2015-01-07 20:22:10
通过将onClick脚本设置为SaveUpdateToActionList(this);,可以传递要单击的元素。
然后,在SaveUpdateToActionList正文中,Cell将引用刚才单击的按钮。然后,您可以沿着DOM走到它所属的TD。
发布于 2015-01-07 20:32:33
你可以试试这个:
document.getElementById(IndexedActionButton).innerHTML = '<input type="Button" name = "EditActionButton" id="EditActionButton" onClick="SaveUpdateToActionList()" value="Edit Action" />';
function SaveUpdateToActionList(event) {
alert(event.target.id);
document.getElementById(Cell).innerHTML = 'Here';
}但是,如果我正确地理解了您想要做的事情,那么您应该有一个事件列表器来捕捉所有单元格中的模糊事件,而不是在每个单元格上附加一个单击按钮.
发布于 2015-01-07 20:45:01
只需将事件侦听器与指定innerHTML属性分开注册:
Document.getElementById(IndexedActionButton).addEventListener('onclick', SaveUpdateToActionList);将以事件对象作为第一个参数调用SaveUpdateToActionList。您可以通过检查event.target属性来访问单击的元素。有关更多信息,请参阅MDN - addEventListener文档
https://stackoverflow.com/questions/27827410
复制相似问题