判断页面上的单选按钮都被选中 RT~~我有一组单选按钮,name为a[1],a[2],a[4],a[8] 由于括号内的数值不是连续的 故不能用传统的遍历方法进行操作求一通用方法验证页面上所有的按钮都被选中 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <form name="form1" method="post" action=""><input type="radio" name="ww" value="1"><input type="radio" name="ss" value="2"> <input name="submit" type="submit" id="submit" onClick="return checkform()" value="提交"></form><script> function checkform(){ var fm = document.form1; //获得表单对象 //alert(fm); for(var i=0;i<fm.length;i++) { if(fm[i].type == "radio") { if(fm[i].checked == false) { return false; } } } return true;}</script> <form name="form1" method="post" action="" onSubmit="return checkform()"><input type="radio" name="ww" value="1"><input type="radio" name="ss" value="2"> <input name="submit" type="submit" id="submit" value="提交"></form> ?? action="" 都没写。 - -` <form name="form1" method="post" action=""><input type="radio" name="ww" value="1"><input type="radio" name="ss" value="2"> <input name="submit" type="submit" id="submit" onClick="return checkform()" value="提交"></form><script> function checkform(){ var fm = document.form1; //获得表单对象 //alert(fm); for(var i=0;i<fm.length;i++) { if(fm[i].type == "radio") { if(fm[i].checked == false) { return false; } } } return true;}</script> 可以提交的啊,我测试过的,action为空的时候提交到本页面,你要写进你要提交到的地方才行你看看你点按钮的时候页面刷新了吗 各位大哥好 我用jquery$('#tianjia input.rad') 通过class获得所有单选按钮,然后我在怎么进行验证都有选择??? $("#tianjia .rad").each(function(){ if(!$(this).attr("checked")) { //这是你要的效果 }});btw:还有更多简单的办法,但是这个最适合你理解。 $("#tianjia .rad").each(function(){ if( !$(this).attr("checked")) { alert(123); return false; } })无论我加不加! 都能弹出123...纳闷 <form name="form1" method="post" action="" id="form1"> <input type="radio" name="ww" value="1"> <input type="radio" name="ss" value="2"> <input type="submit" value="提交" onclick="return checkform();"></form><script src="/jquery-1.3.2.min.js" type="text/javascript"></script><script type="text/javascript">function checkform(){ var istrue = true; $("#form1 :radio").each(function(){ if(!$(this).attr("checked")){ istrue = false; } }); if(!istrue){ alert("单选按钮未都被选中"); } return istrue;}</script> 当单选按钮name相同时只能选则一个,name不同时可全选啊 as2中ExternalInterface.call调用不到JS .net开发的类似桌面系统的代码 jsp页面和ASP做页面那个好 ASP中如何调用js文件中的函数 div 随滚动条滚动,为什么滚动条会一直下拉? 如何根据不同的判断条件引入不同的html文件 对象.removeAttribute("style","",0)是什么意思?请高手告诉我 请问怎样在jsp里对数据表格中的字段进行冻结? 数字的位数检查 js里面 removeChild问题 本人已经没分了忘大家帮得解答,怎么用javascript把结果表示为角度制。 想看一篇文章,有能上外网的兄弟帮忙转过来看下,给分的哦
<form name="form1" method="post" action="">
<input type="radio" name="ww" value="1">
<input type="radio" name="ss" value="2">
<input name="submit" type="submit" id="submit" onClick="return checkform()" value="提交">
</form>
<script>
function checkform()
{
var fm = document.form1; //获得表单对象
//alert(fm);
for(var i=0;i<fm.length;i++)
{
if(fm[i].type == "radio")
{
if(fm[i].checked == false)
{
return false;
}
}
}
return true;
}
</script>
<input type="radio" name="ww" value="1">
<input type="radio" name="ss" value="2">
<input name="submit" type="submit" id="submit" value="提交">
</form>
?? action="" 都没写。 - -`
<input type="radio" name="ww" value="1">
<input type="radio" name="ss" value="2">
<input name="submit" type="submit" id="submit" onClick="return checkform()" value="提交">
</form>
<script>
function checkform()
{
var fm = document.form1; //获得表单对象
//alert(fm);
for(var i=0;i<fm.length;i++)
{
if(fm[i].type == "radio")
{
if(fm[i].checked == false)
{
return false;
}
}
}
return true;
}
</script>
可以提交的啊,我测试过的,action为空的时候提交到本页面,你要写进你要提交到的地方才行
你看看你点按钮的时候页面刷新了吗
$('#tianjia input.rad') 通过class获得所有单选按钮,然后我在怎么进行验证都有选择???
if(!$(this).attr("checked")) {
//这是你要的效果
}
});btw:还有更多简单的办法,但是这个最适合你理解。
if( !$(this).attr("checked"))
{
alert(123);
return false;
}
})无论我加不加! 都能弹出123...纳闷
<input type="radio" name="ww" value="1">
<input type="radio" name="ss" value="2">
<input type="submit" value="提交" onclick="return checkform();">
</form>
<script src="/jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
function checkform(){
var istrue = true;
$("#form1 :radio").each(function(){
if(!$(this).attr("checked")){
istrue = false;
}
});
if(!istrue){
alert("单选按钮未都被选中");
}
return istrue;
}
</script>