我想这样做,使用jQuery勾选复选框:
$(".myCheckBox").checked(true);
or
$(".myCheckBox").selected(true);
这样的事情存在吗?
我想这样做,使用jQuery勾选复选框:
$(".myCheckBox").checked(true);
or
$(".myCheckBox").selected(true);
这样的事情存在吗?
当前回答
你可以试试这个:
$('input[name="activity[task_state]"]').val("specify the value you want to check ")
其他回答
你可以这样做,如果你有身份证来检查它
document.getElementById('ElementId').checked=false
这个要取消选中
document.getElementById('ElementId').checked=真
Use:
$(".myCheckbox").attr('checked', true); // Deprecated
$(".myCheckbox").prop('checked', true);
如果要检查是否选中复选框:
$('.myCheckbox').is(':checked');
如果您正在使用PhoneGap进行应用程序开发,并且您想立即显示按钮上的值,请记住执行此操作
$('span.ui-[controlname]',$('[id]')).text("the value");
我发现,如果没有跨度,无论你做什么,界面都不会更新。
正如@livefree75所说:
jQuery 1.5.x及以下版本
您还可以使用新方法扩展$.fn对象:
(function($) {
$.fn.extend({
check : function() {
return this.filter(":radio, :checkbox").attr("checked", true);
},
uncheck : function() {
return this.filter(":radio, :checkbox").removeAttr("checked");
}
});
}(jQuery));
但是在jQuery的新版本中,我们必须使用如下内容:
jQuery 1.6+
(function($) {
$.fn.extend({
check : function() {
return this.filter(":radio, :checkbox").prop("checked", true);
},
uncheck : function() {
return this.filter(":radio, :checkbox").prop("checked",false);
}
});
}(jQuery));
然后你可以这样做:
$(":checkbox").check();
$(":checkbox").uncheck();
选中和取消选中
$('.myCheckbox').prop('checked', true);
$('.myCheckbox').prop('checked', false);