复选框值始终为“开" [英] Checkbox value is always 'on'

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

问题描述

这是我的复选框

HTML

<label class="checkbox">
    <input id="eu_want_team" name="eu_want_team" type="checkbox">
</label>

JQuery

var eu_want_team = $('#eu_want_team').val();
alert(eu_want_team);

它总是显示ON,是否检查.它有什么问题?

Its always displaying ON, is it checked or not. Whats the problem with it?

推荐答案

使用 .is(':checked') 代替:工作 jsFiddle

Use .is(':checked') instead: Working jsFiddle

var eu_want_team = $('#eu_want_team').is(':checked');
alert(eu_want_team);

或者正如@Itay 在评论中所说,您可以使用 jQuery 的 .prop() 来获取已检查的属性值:

or as @Itay said in comments you can use jQuery's .prop() to get the checked property value:

alert($("#eu_want_team").prop("checked"));

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

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