gpt4 book ai didi

Javascript:无法在 divToHide 的 Else 上读取 null 的属性 'style'

转载 作者:行者123 更新时间:2023-12-03 03:52:00 24 4
gpt4 key购买 nike

如标题所示,错误是“无法读取 null 的属性“style”。

<body class="container">
<div class="row img">
<div class="col-lg-2"><img onclick="divToHide(q1);" class="poster" src="img/batman-begins.jpg">
<div style="display: none;" id="q1">Batman Begins (2005)
<br> FSK: 12 Action, Adventure 16.06.2005
<br>After training with his mentor, Batman begins his fight to free crime-ridden Gotham City from the corruption that Scarecrow and the League of Shadows have cast upon it.
<br> Director: Christopher Nolan</div>
</div>
<div class="col-lg-2"><img onclick="divToHide(q2);" class="poster" src="img/x-men.jpg">
<div style="display: none;" id="q2">X-Men (2000)
<br> FSK: 12 Action, Adventure, Sci-Fi 31.08.2000
<br>Two mutants come to a private academy for their kind whose resident superhero team must oppose a terrorist organization with similar powers.
<br> Director: Bryan Singer</div>
</div>
<div class="col-lg-2 last-Child" style="display: none;"></div>
</div>
<div class="row menu">
<div class="col-lg-2 last-Child1" style="display: none;"></div>
</div>
</body>
<script type="text/javascript">
function divToHide(id) {
var div = document.getElementById(id);
if (div.style.display == 'block') {
div.style.display = 'none';
} else {
div.style.display = 'block';
}
}
</script>

最佳答案

更改 onclick="divToHide(q1);"到 onclick="divToHide('q1');"等等。

关于Javascript:无法在 divToHide 的 Else 上读取 null 的属性 'style',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45122775/

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