作者Toshiya (Kill me softly)
看板Web_Design
標題Re: [問題] javascript控制page display
時間Wed Feb 7 13:15:54 2007
對不起 我自己解出來了... :$
基本上把這二組checkbox設在不同的form裡面就可以了
重點是那四個checkbox 一開始就要設style="visibility:hidden "
簡言之 code長這樣...
(雖然又設display又設visibility好像有點重複...@@)
<script language="javascript">
function select_all() {
document.form2.style.display="";
document.form2.style.visibility="visible";
document.form2.choice2.checked=true;
document.form2.choice3.checked=true;
document.form2.choice4.checked=true;
document.form2.choice5.checked=true;
}
function deselect_all(){
document.form2.style.display="none"; //not showing the form
document.form2.style.visibility="hidden";
document.form2.choice2.checked=false;
document.form2.choice3.checked=false;
document.form2.choice4.checked=false;
document.form2.choice5.checked=false;
}
</script>
<!-- in html -->
<form name="form1" >
<input name="choice1" type="checkbox" value="1" onclick="if (this.checked) {sel
ect_all();}else {deselect_all()}"> click me to see the other 4 choices
</form>
<form name="form2" style="visibility:hidden " >
<br><input name="choice2" type="checkbox" value="2"> choice 2
<br><input name="choice3" type="checkbox" value="3"> choice 3
<br><input name="choice4" type="checkbox" value="4"> choice 4
<br><input name="choice5" type="checkbox" value="5"> choice 5
</form>
--
抱歉 現醜了 :$
--
╭──╮╭──╮╭──╮╭╮╭╮╭──╮╭╮╭╮╭──╮
╰╮╭╯│╭╮││ ─┤│╰╯│╰╮╭╯│╰╯││ ○ │
││ │╰╯│├─ ││╭╮│╭╯╰╮╰╮╭╯│╭╮│
╰╯ ╰──╯╰──╯╰╯╰╯╰──╯ ╰╯ ╰╯╰╯
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 75.85.20.40
1F:推 TonyQ:這和form沒有關係, 拿個div一樣可以寫 ,建議原PO充實DOM觀念 02/07 14:19
2F:→ TonyQ:有些細節不好講, 像是display可以取代visibility來用 :P 02/07 14:20
3F:→ TonyQ:呵 看有沒有人能解釋的清楚點囉 :P 上班中不好打碼 02/07 14:21