简体   繁体   中英

How to check a checkbox jquery

I am trying to use jquery to check my checkbox:

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

My 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/

Thanks in advance!

用这个:

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

The pure JavaScript way:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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