【发布时间】:2019-01-12 12:44:10
【问题描述】:
我已将按钮放在我的表格 EDIT 列中,但该按钮仅适用于第一行点击事件。我正在尝试在单击按钮时打开弹出窗口。只有第一行按钮单击才会打开弹出窗口。
<tbody>
@foreach($books as $data)
<tr>
<td> {{$data['BookID']}} </td>
<td> {{$data['BookName']}} </td>
<td> {{$data['BookUnitPrice']}} </td>
<td><button type="button" value="EDIT" style="height:20px;" id="myBtn"></button></td>
<td> {{$data['BookUnitPrice']}} </td>
</tr>
@endforeach
</tbody>
javascript 代码
<script>
var modal = document.getElementById('myModal');
// Get the button that opens the modal
var btn = document.getElementById("myBtn");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
【问题讨论】:
-
需要更多关于您的问题的描述,顺便说一句
myBtn在您的代码中所有按钮都具有相同的 id