[英]How to make checkbox checked with JQuery 1.3.2?
JQuery version is 1.3.2 jQuery版本是1.3.2
There is a checkbox : 有一个复选框:
<input type="checkbox" id="flag_concept" name="flag_concept" value="1" />
On document load I want it to be checked : 在文档加载时,我希望对其进行检查:
$(document).ready(function(){
{/literal}
{ if $oConcept->flag_encours == 1}
{literal}
$('#flag_concept').attr('checked','checked');
{/literal}
{/if}
{literal}
});
But it doesnt work ! 但这不起作用!
Try using pure javascript instead of jquery if no problem to do it without jquery: 如果没有jquery,可以尝试使用纯JavaScript代替jquery:
document.getElementById("flag_concept").checked = true;
<input type="checkbox" id="flag_concept" name="flag_concept" value="1" />
because all suggestions and answers not working for you, i suggest using .trigger()
like this : 因为所有建议和答案都不适用于您,所以我建议使用
.trigger()
这样:
$( "#flag_concept" ).trigger( "click" );
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> <input type="checkbox" id="flag_concept" name="flag_concept" value="1" />
You can try ; 你可以试试 ;
$('#encours_concept').attr('checked', true);
And Here is a snippet; 这是一个片段;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <html> <script type="text/javascript"> $(document).ready(function(){ $("#chkTest").attr("checked", true); }); </script> <body> <input type="checkbox" id="chkTest" /> </body> </html>
You have given wrong id in jquery: 您在jquery中输入了错误的ID:
Try by applyinh .prop: 通过applyinh .prop尝试:
$('#flag_concept').prop('checked', true);
您可以使用选中的属性,因为在页面上需要它。
<input type="checkbox" id="flag_concept" name="flag_concept" value="1" checked/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.