js 获取radio的选中值 和checkbox 的选中值


关于用 js 获取radio 和checkbox 的选中值问题:

 1、 checkbox 可以获取到是否选中,是的话返回 true ,否则为 false。

 2、 radio 只能循环进行获取选中值,有的话 返回value, 没有的话 返回 undefind


<input type="checkbox" name="ratio" id="check">

<input type="radio" name="lixi" value="1">

<input type="radio" name="lixi" value="2">




function check_form1() {

var radio = '';
var temp = document.getElementsByName("lixi");
 for(var i=0;i<temp.length;i++)
 {
if(temp[i].checked){
 
  var radio = temp[i].value; // 这里获取选中的radio的value值

  
 }
 }

        var check = document.getElementById('check').checked;  // 这里返回 true 或 false


        if(check){
            var ratio = document.getElementById('ratio').value;
if(ratio < 0 || ratio > 100){
alert('比例不正确');
}else{
location.href = url+'&ratio='+ratio;
return false;
}
        }else if(radio){

location.href = url+'&radio='+radio;
return false;

}else{
alert('请填写比例');
 }
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值