[英]How to check if checkbox is checked in asp.net view using Jquery?
I am trying to find out whenever a checkbox on my page is checked and unchecked. 我想找出每当我的页面上的复选框被选中和未选中的情况。 I console log to find out the status, but I am always getting an "unchecked" result.
我通过控制台日志来了解状态,但是我总是得到“未经检查”的结果。 What am I doing wrong?
我究竟做错了什么?
...
<input type="checkbox" id="checkbox_addAuthor" name="checkbox_addAuthor" />
</div>
</form>
@section Scripts
{
<script type="text/javascript">
var checkbox = $('#checkbox_addAuthor');
var authorList = $('#AuthorList');
checkbox.on('click',function(){
if(checkbox.Checked == true)
{
console.log("I am checked")
}
else {
console.log("I am not checked");
}
})
</script>
}
When I run this, the console always prints out "I am not checked". 当我运行此程序时,控制台始终会打印出“我未被选中”。 Cant figure out why.
无法找出原因。
$('#checkbox_addAuthor :checkbox:checked').length > 0;
you can use the prop
你可以用
prop
if($('#checkbox_addAuthor').prop('checked'))
{
// something when checked
}
else {
// something else when not
}
使用$('#checkbox_addAuthor').val() == "on"
来检查复选框的状态
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.