下面的代码可以工作,但是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>发布于 2014-11-21 19:05:12
应该管用的,
function hideShow() {
var e = document.getElementById('divHR');
if(e.style.display != 'none')
e.style.display = 'none';
else
e.style.display = 'block';
}您的div样式显示属性可能不会设置“块”。如果是这样,那么您的代码集就会阻塞display属性。
https://stackoverflow.com/questions/27067835
复制相似问题