哪里出错了?document.getElementById('mjbox').style.display='none';

来源:百度知道 编辑:UC知道 时间:2024/06/07 03:46:27
<script>
function check(){
if(document.addkp.fkkp[0].checked){

document.getElementById('mjbox').style.display='none';
document.getElementById('rmbbox').style.display='';

}
}
</script>

<input checked="checked" type=radio name="fkkp" value=0>
<input type=radio name="fkkp" value=1>

<div id=mjbox>11</div>
<div id=rmbbox>22</div>

<script>check()</script>

----------------------------------------------

上面是代码,实现不了我想要的功能,我想要默认的情况下第一个RADIO被选中,然后执行这两行:
document.getElementById('mjbox').style.display='none';
document.getElementById('rmbbox').style.display='';
可提示我以上两行出现错误,缺少对象

别的估计倒没有错,应该是上面两行的问题,不知道哪里错了,请高手帮忙~
/
----------------------------------------------------
我也用过onclick,可这个radio有没有被选中不是

你上面的document.addkp.fkkp[0].checked不对,而“addkp”不知道从那里来的,我把你的程序改了一下,可以运行的:

<script>
function check(){
var obj=document.getElementsByName("fkkp");
if(obj[0].checked){

document.getElementById('mjbox').style.display='none';
document.getElementById('rmbbox').style.display='';

}
}
</script>

<input checked="checked" type=radio name="fkkp" value=0>
<input type=radio name="fkkp" value=1>

<div id=mjbox>11</div>
<div id=rmbbox>22</div>

<script>check()</script>

<script defer>
function check(){

试试。
你要保证document.get......的id在调用前是存在的

把check绑定到radio的oncheck事件上
这样修改:

<input checked="checked" type=radio name="fkkp" onclick="check()" value=0>

addkp从哪来的呀