注册 登录
编程论坛 J2EE论坛

问大家一个JavaScript的问题??急!!

999hits 发布于 2007-03-15 16:05, 929 次点击

为什么我点击第二个radio时候,那两个文本框没有出现啊??
<html>
<head>
<title>
test
</title>
</head>
<body bgcolor="white">

<input type="radio" name="select" id="selectRadio" onclick="change()"/>
<input name="bookNum" type="text" id="bookNum" style="display:none"/>
<input name="prMoney" type="text" id="prMoney" style="display:none"/>

<input type="radio" name="select" id="selectRadio" onclick="change()"/>
<input name="bookNum" type="text" id="bookNum" style="display:none"/>
<input name="prMoney" type="text" id="prMoney" style="display:none"/>
</script>
<script language="javascript">
function change()
{
if (document.getElementById("selectRadio").checked)
{
document.getElementById("bookNum").style.display = "inline";
document.getElementById("prMoney").style.display = "inline";
document.getElementById("selectRadio").checked = true;
}
else
{
document.getElementById("bookNum").style.display = "none";
document.getElementById("prMoney").style.display = "none";
document.getElementById("selectRadio").checked = false;
}
}
</script>
</body>
</html>

11 回复
#2
JavaEE52007-03-15 18:26
ID都一样,所以错了
你想做什么样的效果?
你这样做不合理呀
#3
999hits2007-03-15 18:55

就是有几个checkbox(个数未定),当你选中一个checkbox时候,相对应的显示两个文本框,不选中的时候,两个文本框消失,就是这样了,各位帮个忙写一下,我现在及需要,但是不太懂JS,所以拜托各位了

#4
支离破碎2007-03-16 08:47

试一下这样。

程序代码:

<html>


<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">
<title>New Page 1</title>
<script>
    function controlText(){
        var text=document.getElementById(\"textInput\");
        var showText=document.getElementById(\"showText\");
        var hidenText=document.getElementById(\"hidenText\");
        
        if(showText.checked){
            text.style.display=\"\";        
        }
        if(hidenText.checked){
            text.style.display=\"none\";        
        }   
   
    }



</script>



</head>


<body>
    <div id=\"textInput\">
    <input type=\"text\" name=\"T1\" size=\"20\">
    <input type=\"text\" name=\"T2\" size=\"20\">
    </div>
    <p>
        <input type=\"radio\" value=\"V1\" checked name=\"R1\" id=\"showText\" onclick=\"controlText()\">show
        <input type=\"radio\" value=\"V2\" name=\"R1\" id=\"hidenText\" onclick=\"controlText()\">hiden
    </p>
</body>


</html>

#5
风月_无边2007-03-16 09:59
好像是没什么效果!!
#6
支离破碎2007-03-16 10:08
COPY过去就能直接运行,怎么会没效果?
#7
风月_无边2007-03-16 10:24
我试了,radio不起作用,另外如何首先让两个text不显示出来
#8
支离破碎2007-03-16 10:50

不可能不起作用,如果想一开始就不显示,只用再写一段脚本,在body的onload事件中加载就可以了。

程序代码:

<html>


<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">
<title>New Page 1</title>
<script>
    function controlText(){
        var text=document.getElementById(\"textInput\");
        var showText=document.getElementById(\"showText\");
        var hidenText=document.getElementById(\"hidenText\");
        
        if(showText.checked){
            text.style.display=\"\";        
        }
        if(hidenText.checked){
            text.style.display=\"none\";        
        }   
   
    }


     function hideTextForInit(){
           var text=document.getElementById(\"textInput\");


            text.style.display=\"none\";      


   }


</script>



</head>


<body onload=\"hideTextForInit()\">
    <div id=\"textInput\">
    <input type=\"text\" name=\"T1\" size=\"20\">
    <input type=\"text\" name=\"T2\" size=\"20\">
    </div>
    <p>
        <input type=\"radio\" value=\"V1\" name=\"R1\" id=\"showText\" onclick=\"controlText()\">show
        <input type=\"radio\" value=\"V2\" name=\"R1\" id=\"hidenText\" onclick=\"controlText()\">hiden
    </p>
</body>


</html>




#9
喃瑟2007-03-16 10:53
display:none
#10
支离破碎2007-03-16 10:55
可能他用的不是IE,如果用FIRE。。的可能脚本不支持,就要换面LS上的写法了。
#11
999hits2007-03-16 11:41
问题以解决,谢谢各位
#12
风月_无边2007-03-16 11:45
不错,这个可以了!!
1