[英]“First Click” of Button does not hide div
下面的代码有效,但是onclick仅在第二次单击按钮后才可使用该功能。 为什么在第一次单击该按钮时要隐藏该文本区域,我需要做什么?
我的JavaScript:
function hideShow() {
var e = document.getElementById('divHR');
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
html
<button id="btnHideShow" onclick="hideShow();">
<img src="Images/arrow1.bmp" alt="Right Arrow icon" style="width:13px;
height:13px; border:0px;" />
Hide or show Human Resources Information
</button>
<div id="divHR" class="showHRInfo">
<h3 id="h3Inline">About Windsurf Human Resource (HR) division </h3>
<p id="pWindSurfHR" > Windsurf values and respects its employees very highly.
Should you have any problem, questions or concerns please
contact our Human Resource division. They are always at your service.
</p>
</div>
它应该工作,
function hideShow() {
var e = document.getElementById('divHR');
if(e.style.display != 'none')
e.style.display = 'none';
else
e.style.display = 'block';
}
您的div样式显示属性可能未设置“阻止”。 如果是这样,则您的代码集将阻塞您的显示属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.