gpt4 book ai didi

javascript - javascript onclick 属性如何用于循环数组的更多输出?

转载 作者:行者123 更新时间:2023-11-29 02:21:48 24 4
gpt4 key购买 nike

//我的问题是当我的 checkit() 函数被调用时,它只在数组中的第一个项目旁边显示一次 check.png 图像。

<?php
require 'connectit.php';

if($result = $db->query("SELECT * FROM people ORDER BY id")) {
if($count = $result->num_rows) {

echo "<h3>He's got $count bills to pay.</h3>";
echo "<p>";
while($row = $result->fetch_object()) {
echo "<div id=\"check\" onClick=\"checkit();\"><img id=\"img\" src=\"\" /></div>";
$id = $row->id;

echo $row->bill_name, ': $', $row->bill_cost,
' ',"<a href=\"delete_id.php?id=" . $id . "\">X</a><br/><br/>";
echo "</p>";
}
}
}
?>
//javascript onclick function
<script type="text/javascript">
function checkit(){
document.getElementById("img").src = "check.png";
//needed to put a line through the text, to mark through it but can't figure that out either. I tried this.
document.getElementById("p").style.texttransform = "underline"; //didn't work for me.
}
</script>

最佳答案

试试这段代码:

var list = document.getElementsByTagName("img");

for(var i=0;i<list.length;i++) {
list[i].src = "check.png";
}

obs:我没有测试过。

更新:

var list = document.getElementsByTagName("img");

for(var i=0;i<list.length;i++) {
if(list[i].id == 'some_id') {
list[i].src = "check.png";
}
}

关于javascript - javascript onclick 属性如何用于循环数组的更多输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30467316/

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