当前位置: 代码迷 >> Java Web开发 >> 问大家一个JavaScript的问题??急!!
  详细解决方案

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

热度:100   发布时间:2007-03-15 16:05:03.0
问大家一个JavaScript的问题??急!!

为什么我点击第二个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>

搜索更多相关主题的帖子: JavaScript  input  name  type  

----------------解决方案--------------------------------------------------------
ID都一样,所以错了
你想做什么样的效果?
你这样做不合理呀
----------------解决方案--------------------------------------------------------

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


----------------解决方案--------------------------------------------------------

试一下这样。

程序代码:

<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>


----------------解决方案--------------------------------------------------------
好像是没什么效果!!
----------------解决方案--------------------------------------------------------
COPY过去就能直接运行,怎么会没效果?
----------------解决方案--------------------------------------------------------
我试了,radio不起作用,另外如何首先让两个text不显示出来
----------------解决方案--------------------------------------------------------

不可能不起作用,如果想一开始就不显示,只用再写一段脚本,在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>




----------------解决方案--------------------------------------------------------
display:none
----------------解决方案--------------------------------------------------------
可能他用的不是IE,如果用FIRE。。的可能脚本不支持,就要换面LS上的写法了。
----------------解决方案--------------------------------------------------------
  相关解决方案