简体   繁体   English

如何检查复选框jQuery

[英]How to check a checkbox jquery

I am trying to use jquery to check my checkbox: 我正在尝试使用jquery来检查我的复选框:

<div class="checkbox">
  <label><input type="checkbox" value="" id="restricted_access">Restricted Access?</label>
</div>

My js: 我的js:

$('#restricted_access').prop('checked', true);

But this just returns 但这只是返回

[<input type=​"checkbox" value id=​"restricted_access" checked=​"checked">​]

Can someone help? 有人可以帮忙吗?

Here's my fiddle: 这是我的小提琴:

https://jsfiddle.net/ysh1wt5y/ https://jsfiddle.net/ysh1wt5y/

Thanks in advance! 提前致谢!

用这个:

$('#restricted_access').prop('checked', true);

The pure JavaScript way: 纯JavaScript方式:

 document.getElementById('restricted_access').checked = true; 
 <div class="checkbox"> <label> <input type="checkbox" value="" id="restricted_access">Restricted Access?</label> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM