我試圖創建一個DIV &跨度內DIV &跨度。Div跨度內的Div跨度.... DivSpanception
我創建了顯示/隱藏代碼,允許某人點擊「全部顯示」或「全部隱藏」,所有的Spans正常打開和關閉。或者用戶可以單獨點擊DIV並打開該部分。
<script type="text/javascript">
function displayMap() {
document.getElementById('map_canvas').style.display="block";
initialize();
}
function showhide(id) {
if (document.getElementById) {
obj = document.getElementById(id);
if (obj.style.display == "") {
obj.style.display = "none";
} else {
obj.style.display = "";
}
}}
function hide(id) {
if (document.getElementById) {
obj = document.getElementById(id);
if (obj.style.display == "none") {
obj.style.display = "none";
} else {
obj.style.display = "none";
}
}}
function hideall(id1,id2,id3,id4,id5,id6,id7) {
var status1 = document.getElementById(id1).style.display;
var status2 = document.getElementById(id2).style.display;
var status3 = document.getElementById(id3).style.display;
var status4 = document.getElementById(id4).style.display;
var status5 = document.getElementById(id5).style.display;
var status6 = document.getElementById(id6).style.display;
var status7 = document.getElementById(id7).style.display;
if ((status1 == 'none') || (status2 == 'none') || (status3 = 'none') || (status4 = 'none') || (status5 == 'none') || (status6 == 'none') || (status7 == 'none')) {
hide(id1); hide(id2); hide(id3); hide(id4); hide(id5); hide(id6);hide(id7); return;
} IF((狀態1 = '無')||(狀態= '無')!| |(status3!='none')||(status4!='none')||(status5 =='none')||(status6 =='none')||(status7 =='none')) {hide(id1);隱藏(ID2);隱藏(ID3);隱藏(ID4);隱藏(ID5);隱藏(ID6);隱藏(ID7);返回; }}
function show(id) {
if (document.getElementById) {
obj = document.getElementById(id);
if (obj.style.display == "") {
obj.style.display = "";
} else {
obj.style.display = "";
}
}}
function showall(id1,id2,id3, id4, id5, id6, id7) {
var status1 = document.getElementById(id1).style.display;
var status2 = document.getElementById(id2).style.display;
var status3 = document.getElementById(id3).style.display;
var status4 = document.getElementById(id4).style.display;
var status5 = document.getElementById(id5).style.display;
var status6 = document.getElementById(id6).style.display;
var status7 = document.getElementById(id7).style.display;
if ((status1 == 'none') || (status2 == 'none') || (status3 = 'none') || (status4 = 'none') || (status5 = 'none') || (status6 = 'none') || (status7 == 'none')) {
show(id1); show(id2); show(id3); show(id4); show(id5); show(id6);show(id7); return;
}
if ((status1 != 'none') || (status2 != 'none') || (status3 != 'none') || (status4 != 'none') || (status5 != 'none') || (status6 != 'none') || (status7 == 'none')) {show(id1); show(id2); show(id3); show(id4); show(id5); show(id6);show(id7); return;
}
}
</script>
我目前有:
<center>
<div style="background-color:black; width:80%; cursor:pointer;hand" onClick="showhide('id5'); return(false);"><table width="100%"><tr><td width=80% align=left><font color="white" size="4"><strong> General Airport Information</strong></font></td><td align=right><font color="white" size="1">Click to Expand/Close</font></td></tr></table></div>
<span id="id5" style="display: none">
...HIDDEN TEXT...
</span>
</center>
<br>
我想要什麼:
<center>
<div style="background-color:black; width:80%; cursor:pointer;hand" onClick="showhide('id6'); displayMap(); return(false);"><table width="100%"><tr><td width=80% align=left><font color="white" size="4"><strong> Airport Maps</strong></font></td><td align=right><font color="white" size="1">Click to Expand/Close</font></td></tr></table></div>
<span id="id6" style="display: none">
<center>
<div style="background-color:black; width:80%; cursor:pointer;hand" onClick="showhide('id7'); displayMap(); return(false);"><table width="100%"><tr><td width=80% align=left><font color="white" size="4"><strong> Airport Maps hiddent toolbar</strong></font></td><td align=right><font color="white" size="1">Click to Expand/Close</font></td></tr></table></div>
<span id="id7" style="display: none">
...HIDDEN TEXT...
</span>
</center>
</span>
</center>
<br>
目前我已經創建了內部DIV/SPAN,並且我可以單擊工具欄並打開它,但是當我單擊「全部顯示」/「全部隱藏」時,它無法正常工作。
我該如何解決這個問題?
爲什麼要在'showall()'和'hideall()'中檢索顯示狀態。只需設置所有顯示與否。 – Teemu 2012-03-14 13:29:24
你真的不應該使用