是实现了目的,但是如果页面上有100个控件都要显示Div,那岂不是要在new Array后面写上100个id?
解决方案 »
- window对象不支持onclick事件吗
- lightbox 2.5 无法在父窗口打开 求解
- 【Ext小白】查询时如何把输入的条件提交到JSP,在JSP里如何获取呢?
- radio 是否选中
- Javascript 中radiobuttonlist赋值问题
- js 地址不发生变化 跳转
- 在showModalDialog 中弹出页面A,在弹出的页面A中向自己提交(form)为何又弹出一个页面?
- 求教:下面这句单引号双引号该怎么写
- 自己设置自己窗口的属性(比如:大小、位置、工具栏、菜单栏、地址栏等)
- 使用winsock组件问题-在线等待
- 学习JavaScript,推荐书籍!!
- 请问如何修改alert和confirm()弹出窗口的文字字体颜色
<div id="fdfi758ifd">1个是<div id="fgdfsfd">1个是不是</div>真不知道啊不是</div>
<div id="shiybClick" onclick="hiddenOther(this);" style="cursor:pointer;" >请点击此处选择...<div>这里的内容也是噢!</div> </div >
<div id="fdu5eusfd">1个是不是</div>
<div id="fdfi758ifd">1个是<div id="fgdfsfd">1个是不是</div>真不知道啊不是</div>
<div id="fdu5eusfd">1个是不是</div>
<div id="fdfi758ifd">1个是<div id="fgdfsfd">1个是不是</div>真不知道啊不是</div>
<div id="fdu5eusfd">1个是不是</div>
<div id="fdfi758ifd">1个是<div id="fgdfsfd">1个是不是</div>真不知道啊不是</div>
<p>这里是P标签</p>
这里不应该隐藏的~!
<script type="text/javascript">
$ = function(d) {document.getElementById(d);}
function hiddenOther(thisDiv) {
var temp = thisDiv;
while(temp.previousSibling) {
if(temp.nextSibling.nodeName == 'DIV') temp.previousSibling.style.display="none";
temp = temp.previousSibling;
}
var temp = thisDiv;
while(temp.nextSibling) {
if(temp.nextSibling.nodeName == 'DIV') temp.nextSibling.style.display="none";
temp = temp.nextSibling;
}
}</script>你试试这种思路行不行~但不知道为什么我这个代码无法在Firefox下运行,
<html>
<script>
function show(){
var shiyDiv=document.getElementById("shiybDiv");
shiyDiv.style.display="";
shiyDiv.iShow=true;
}
function hide(){
var shiyDiv=document.getElementById("shiybDiv");
if(!shiyDiv.iShow){
document.getElementById("shiybDiv").style.display="none";
}
shiyDiv.iShow=false;
}
</script>
<body onload="document.getElementById('shiybDiv').iShow=false;" onclick="hide()">
<div id="shiybDiv" style="display:none;" onclick="show()" >aadasfsad </div >
<div id="shiybClick" onclick="show()" style="cursor:pointer;" >请点击此处选择... </div >
</body>
</html>
onmouseout="document.getElementById('shiybDiv').style.display='none';"
style="cursor:pointer;background-color:blue;width:300px;">请点击此处选择... </div>
<div id="shiybDiv" style="display:none;background-color:yellow;width:200px;"
onmouseover="document.getElementById('shiybDiv').style.display='';"
onmouseout="document.getElementById('shiybDiv').style.display='none';">
aadasfsad <br>fdasf<br>dfdddd<br>ddddd</div>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
<div id="shiybDiv" style="display:none;" >aadasfsad </div >
<div id="shiybClick" style="cursor:pointer;">请点击此处选择...</div >
<div style="cursor:pointer;">check1</div >
<div style="cursor:pointer;">check2</div >
<div id="shiybClick1" style="cursor:pointer;">请点击此处选择...</div >
<div style="cursor:pointer;">check3</div >
</body>
</html>
<script language="javascript">
document.onclick = function()
{
//document点击时隐藏指定元素 因为document是冒泡的最后一层所以只要中途终止冒泡就不会触发这个事件
document.getElementById('shiybDiv').style.display='none';
}
window.onload = function()
{
var showSrc = ['shiybDiv','shiybClick','shiybClick1'];//允许点击的ID数组
var fc = function(event)//事件方法
{
document.getElementById('shiybDiv').style.display="";//显示指定元素
event.cancelBubble=true;//终止冒泡
}
for(var i=0,l=showSrc.length;i<l;i++)//遍历每个ID
document.getElementById(showSrc[i]).onclick = fc;//给这个元素的onclick事件加上方法
}
</script>