JavaScript隐藏/可见脚本在第二次单击后不会隐藏
JavaScript hide/Visible script doesnt hide after 2nd click
我的脚本有问题,当我点击隐藏div时,它不起作用。但对于使div可见,它的工作非常完美。
你能解释一下并帮我吗?
function visibilite(id) {
var divs = document.getElementsByTagName('div');
for(var no=0;no<divs.length;no++){
if(divs[ no].className=='divs bouton' || divs[ no].className=='divs'){ // Target div which called "divs" OR called "divs bouton"
divs[ no].style.display = "none"; // hide them all
}
}
document.getElementById(id).style.display = "block"; // visible
}
HTML代码:
<head>
<link href="ress/css/stylesheet.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/baseScript.js"></script>
<style type="text/css">
/*<![CDATA[*/
.divs {display:none;padding:5px;margin:10px;}
/*]]>*/
</style>
<script type="text/javascript">
//<![CDATA[
function visibilite(id) {
var divs = document.getElementsByTagName('div');
for(var no=0;no<divs.length;no++){
if(divs[ no].className=='divs bouton' || divs[ no].className=='divs'){ // Target div which called "divs" OR called "divs bouton"
divs[ no].style.display = "none"; // hide them all
}
}
document.getElementById(id).style.display = "block"; // visible
}
//]]>
</script>
</head>
<body>
<div style="width:250px;margin:auto;" class="txtlinks" id ="headontainer">
<div class="col marginR">
<a style="float:left; margin-right:10px;" href ="#">Installation Kit</a><a href ="#">FAQs</a><br />
</div>
</div>
<div style="width:700px;margin-left:auto;margin-right:auto;" id ="maincontainer">
<div style="padding-bottom:75px;" onmouseover="this.style.border='1px solid blue'" onmouseout="this.style.border='0px'" id="work_1" >
<a style="text-transform:none;" href="javascript:visibilite('opt1');">
<div>
<span class="blctxt blueblc">Getting to know Office 365</span>
<br />
<span style="color: rgb(80, 81, 80); font-family: 'segoe ui', arial, tahoma; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 20px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none;">
Check out see some of the ways Office 365 can help people get things done,
better, together</span>.
</div>
</a>
<div id="opt1" class="divs bouton">
<br />
<br />
<a style="text-decoration: none; color:white;" href="http://aka.ms/o365booklet" target="_blank">Download PDF</a>
</div>
</div>
非常感谢。
您可以简单地编写以下内容:
function visibilite() {
var divs = document.getElementsByClassName('divs');
var bouton = document.getElementsByClassName('bouton');
if(divs.style.display == 'hidden' || bouton.style.display == 'hidden')
{
bouton.style.display = "block";
divs.style.display = "block"; // visible
}
else{
bouton.style.display = "hidden";
divs.style.display = "hidden";
}
}
相关文章:
- 在单击任何位置时隐藏元素,而不检查每次DOM单击
- 单击按钮后如何逐个调用分区,上一个分区将隐藏
- JavaScript-在手机上不工作的情况下,在外部单击时隐藏元素
- 单击时显示,再次单击时隐藏
- JQuery在单击正文时隐藏上下文菜单
- JQuery在单击时停止显示/隐藏
- 如何隐藏按钮单击事件上的占位符
- 单击时隐藏弹出窗口
- jquery单击隐藏的复选框
- 在开始时隐藏FX.slide内容,而不是在单击后隐藏
- 如何在单击按钮时显示一个分区,同时隐藏另一个分区
- 单击其他元素或鼠标向上时隐藏输入框,但保留一次焦点
- 当链接单击-jQuery时,第二层下拉列表将隐藏
- 在显示/隐藏中单击时删除的文本
- jQuery单击隐藏其父元素
- 单击javascript按钮显示/隐藏Div元素
- 单击表单1中的按钮:更改表单2中隐藏输入的值(纯javascript)
- 隐藏选择选项,并在单击定义的选项后显示它们
- 隐藏单击的元素,并使用jQuery在元素之后立即显示该元素
- 如何在angularjs中隐藏单击的按钮1和显示按钮2以及单击按钮2隐藏按钮2和显示按钮1