作者bigair (广大的天空)
看板Web_Design
标题Re: [问题] 表单问题
时间Wed Jul 5 23:46:54 2006
※ 引述《rushcat (嗯)》之铭言:
: 目前是想做两个radio 当 radio a 的值为1的时候 radio b 才会跑出来
: 爬了一下文 有找到div的用法@"@
: 但是有点怪怪的XD
: <script>
: function show(test){
: var obj = document.getElementById("aaa");
: if (obj.value=="1"){
: test.style.display='';
: test.Open="";
: }
: else if (obj.value=="2"){
: test.style.display='none'
: test.Closed="";
: }
: }
: </script>
: <div id="test1" style="display:block" >
: <input type="radio" name="a" value="1" id="aaa" onblur="show(test2)" />
: <input type="radio" name="a" value="2" id="aaa" onblur="show(test2)" />
: </div>
: <div id="test2" style="display:none">
: <input type="radio" name="b" value="1" />
: <input type="radio" name="b" value="2" />
: </div>
: 目前是按a 第二个 b不会出来 按第一个会出来
: 但是再按一次第二个 他还是不会不见XD (有点像绕口令)
: 简单来说 就是出的来 收不回去...orz
: 请问是哪里出了错
: 感激大家!!~
试写了一下,应该有你要的要求吧?
主要就是利用 javascript 去触控 radio 的 onClick,
然後控制css的 display = none or block,
作这动作的同时,把radio b 的checked也清空
----
<html>
<head>
<style>
.status1 {
display: none;
}
.status2 {
display: block;
}
</style>
<script>
function emptyRadio() {
for(i=0;i<document.form1.b.length;i++) {
if(document.form1.b[i].checked){
document.form1.b[i].checked = false;
break;
}
}
}
</script>
</head>
<form name="form1">
<input type="radio" name="a" value="1"
onClick='test.className="status2";emptyRadio();' />a1
<input type="radio" name="a" value="2"
onClick='test.className="status1";emptyRadio();' />a2
<div id="test" class="status1">
<input type="radio" name="b" value="1" />b1
<input type="radio" name="b" value="2" />b2
</div>
</form>
</html>
--
︿●′︿诚徵花映塚对战相手 ( ̄▽ ̄#)﹏﹏
●﹀
●●〈﹨
http://www.wretch.cc/blog/bigair
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.167.76.224
※ 编辑: bigair 来自: 218.167.76.224 (07/05 23:47)
1F:推 rushcat:感激@"@ 我会努力理解他的...XDDD 辛苦了!~ 07/05 23:48
※ 编辑: bigair 来自: 218.167.76.224 (07/05 23:56)
2F:推 rushcat:我想问的是 form1.b.Checked=false; emptyRadio(); 07/05 23:56
3F:→ rushcat:这两个作用是不是一样@"@ 都是清空b的值!? 07/05 23:57
4F:→ bigair:form1.b.Checked=false; 是我脑残写错的东西.. 忘了他吧 :P 07/06 00:00
5F:推 rushcat:XD 好 我忘记他了!~ 07/06 00:04