gpt4 book ai didi

javascript - 如何更改开盘和收盘详情/摘要的图片?

转载 作者:行者123 更新时间:2023-12-05 04:36:42 25 4
gpt4 key购买 nike

这是我的第一个 JavaScript。这花了很多时间,但无法正常工作。

显然,它应该做的是在“详细信息/摘要”部分打开时更改图片。仅供引用,这是 this problem 的后续行动我正在努力解决。有人看到我做错了什么吗?

<body>
<script type="text/javascript">
function changeImage(a) {
document.getElementById("img").src = a;
}
details.addEventListener("toggle", event => {
if (details.open) {
changeImage("https://via.placeholder.com/50/ff0000");
} else {
changeImage("https://via.placeholder.com/50/0000ff");
}
});
</script>

<details>
<summary>
<table>
<td width="64">#910</td>
</table>
</summary>
<table>
<td width="64">#910</td>
</table>
</details>

<img id="img" src='https://via.placeholder.com/50'>
</body>

最佳答案

这是您缺少的部分:const details = document.querySelector('details')。然后就可以了。

    function changeImage(a) {
document.getElementById("img").src = a;
}
const details = document.querySelector('details')
details.addEventListener("toggle", event => {
if (details.open) {
changeImage("https://via.placeholder.com/50/ff0000");
} else {
changeImage("https://via.placeholder.com/50/0000ff");
}
});
<body>
<script type="text/javascript">

</script>

<details>
<summary>
<table>
<td width="64">#910</td>
</table>
</summary>
<table>
<td width="64">#910</td>
</table>
</details>

<img id="img" src='https://via.placeholder.com/50'>
</body>

关于javascript - 如何更改开盘和收盘详情/摘要的图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70776623/

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