【发布时间】:2017-06-22 09:19:56
【问题描述】:
<? foreach(.........){
<select id = "RelationshipSelect" name = 'RelationshipSelect' disabled>
//some codes implement
</select>`enter code here`
<input type = 'text' value = "<? echo ... ?>" id = "affectedSystems_0" name = 'affectedSystems_0' readonly>
<input type = "button" id = 'findAffectedSystems_0' value = 'Find' disabled>
<input type = "button" id = 'removeAffectedSystems_0' value = 'Remove' disabled>
<?}?>
as showing in the photo, CI Relationship Field data are retrieve using foreach loop.
在 javascript 文件中,我将“findAffectedSystems_0”称为查找按钮 ID,但它仅适用于“查找”按钮的第一行。我应该怎么做才能让所有的按钮都可以点击。
document.getElementById("findAffectedSystems_0").addEventListener("click", function (){
//some codes work
});
【问题讨论】:
-
使按钮的 ID 唯一。
-
查找和删除按钮不能有相同的
id。你需要让它像findAffectedSystems_0,findAffectedSystems_1一样动态化 -
谢谢@JigarShah。但是我如何在循环中获取按钮的动态 id。请帮助我,我是这方面的新手
-
不!为所有按钮分配一个类,例如class="btn",然后使用 document.getElementsByClassName
-
@A.S 我已经添加了示例代码。
标签: javascript php foreach