测试 测试 测试 测试 提示:getEmementsByName方法的作用是根据 NAME 标签属性的值获取对象的集合。 样例一 < html > < head > < meta http-equiv ="Content-Type" content ="text/html; charset=gb2312" > < title > 判断单选框或复选框是否选中 </ title > </ head > < body > < input name ="radio1" type ="radio" value ="test" > < button onClick ="alert('单选项'+(document.getElementsByName('radio1')[0].checked? '':'没有')+'选中')" > 测试 </ button >< br > < input name ="radio1" type ="radio" value ="test" > < button onClick ="alert('单选项'+(document.getElementsByName('radio1')[1].checked?'':'没有')+'选中')" > 测试 </ button >< br > < input name ="checkbox1" type ="checkbox" value ="test" > < button onClick ="alert('多选项'+(document.getElementsByName('checkbox1')[0]. checked?'':'没有')+'选中')" > 测试 </ button >< br > < input name ="checkbox1" type ="checkbox" value ="test" > < button onClick ="alert('多选项'+(document.getElementsByName('checkbox1')[1].checked?'':'没有')+'选中')" > 测试 </ button > 提示:getEmementsByName方法的作用是根据 NAME 标签属性的值获取对象的集合。 </ body > </ html > 样例二: <script language="JavaScript"> function check(){ var flag=0 for(i=0;i < form name ="myform" action ="" method ="" onsubmit ="return check()" > < input type ="radio" name ="picno" value ="1" > < input type ="radio" name ="picno" value ="2" > < input type ="radio" name ="picno" value ="3" > < input type ="submit" value ="Submit" > </ form > < script language ="JavaScript" > ... function check()...{ var flag=0 for(i=0;i<myform.picno.length;i++) if(myform.picno[i].checked==true)...{ flag=1 break } if(!flag)...{ alert("请先选择更换图片的位置") return false }} </ script >