Checkbox value is always 'on'
This question already has an answer here:
Use .is(':checked')
instead: Working jsFiddle
var eu_want_team = $('#eu_want_team').is(':checked');
alert(eu_want_team);
or as @Itay said in comments you can use jQuery's .prop()
to get the checked property value:
alert($("#eu_want_team").prop("checked"));
<label class="checkbox">
<input id="eu_want_team" name="eu_want_team" type="checkbox" value="somevalue">
</label>
<script>
var ele = document.getElementById("eu_want_team");
if(ele.checked)
alert(ele.value)
</script>
Have a quick look at this answer for checking if a checkbox is checked.
How to check whether a checkbox is checked in jQuery?
But basically you want to do something like below to check its value:
if ($("#element").is(":checked")) {
alert("I'm checked");
}
链接地址: http://www.djcxy.com/p/9512.html
上一篇: 获取当前状态的复选框jquery
下一篇: 复选框值始终为'on'