复选框值为0或1 [英] checkbox value 0 or 1

查看:699
本文介绍了复选框值为0或1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在很多情况下,我的复选框如下

In many cases, I have checkboxes as below

 <input type="checkbox" name="custom7" value="1" id="custom7"
 checked="checked"> <label for="custom7">Email me more info?</label>

现在,当复选框被选中时,值应该为1,如value = 1。如果复选框未选中,我希望该值为零,如value = 0。我怎样才能做到这一点?

Now when the checkbox is checked the value should be 1 as in value=1 . If the checkbox is unchecked, I want the value to be zero as in value=0. How can I do this?

推荐答案

感谢您在

Thanks worked as in

$('#custom7').on('change', function(){
   this.value = this.checked ? 1 : 0;
   // alert(this.value);
}).change();

link: http://jsfiddle.net/WhQaR/

这篇关于复选框值为0或1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆