【发布时间】:2022-02-11 19:59:44
【问题描述】:
我需要使用 JS 让图像标题在 1 次鼠标单击时出现并在下次单击时消失。我无法弄清楚为什么当我单击带有 onclick 事件和函数在外部 JS 上使用的图像时没有出现图像标题。抱歉,如果我在问题上犯了任何错误,因为这是我在论坛上的第一篇文章。
HTML
<div id="section1" >
<h1>Pictures from my vacation</h1>`enter code here`
<figure style="float: left;" >
<img src="Photos/p1.jpg" title="Beach" value="hide/show" onclick="showOrHide()">
<figcaption id="showthis" style="visibility: hidden;">Waterton Beach</figcaption>
</figure>
<p>Beautiful and Sunny day at Wateron last year. Taking Ferry to explore around the late and natural beauty surrounded there. It was a beatiful day and beach and small town with full of visitors. Hope to back to this beautiful small town on summer break.
</p>
</div>
JS
函数 showOrHide() {
if (show=="false") {
document.getElementById("showthis").style.visibility="visible";
show="true";
}
else {
//show is true
document.getElementById("showthis").style.visibility="hidden";
show="false";
}
}
【问题讨论】:
-
你在哪里声明
show变量?
标签: javascript html