我可以启用并检查表单上的所有字段,但我无法自动启用字段! 这是我的代码(现在正在工作):
$(document).ready(function(){
$("#lnk_checkall").click(function() {
if ($(this).attr("checked"))
{
$("input:checkbox.fb_chk").attr("checked", "checked");
$("input:checkbox.fb_chk").trigger("change");
}
else
{
$("input:checkbox.fb_chk").removeAttr("checked");
$("input:checkbox.fb_chk").trigger("change");
}
});
$("tr.photo_fb_item .fb_chk").change(function() {
var parent = $(this).parent().parent();
if ($(this).attr("checked") == "checked")
{
$("input.d", parent).removeAttr("disabled");
$("textarea.d", parent).removeAttr("disabled");
}
else
{
$("input.d", parent).attr("disabled", "disabled");
$("textarea.d", parent).attr("disabled", "disabled");
}
});
});
这是我的页面:
$out .= '<input type="checkbox" name="checkall" id="checkall">Select All<br>';
$out .= '<tr class="photo_fb_item">'
. '<td><input type="checkbox" class="fb_chk" name="PICSOURCE[]" value="' . $item['source'] . '"/>'
有人可以给我添加代码来检查所有方框吗?
答案 0 :(得分:0)
$(this).prop("checked", true);
应该可以检查您的复选框 有关详细信息,请参阅以下帖子
Setting "checked" for a checkbox with jQuery?
如果启用了checkall则检查所有字段的代码,否则取消选中
$('#checkall').click(function() {
if($(this).attr('checked')== true) {
$('.fb_chk').each(function() {
$(this).prop("checked", true);
})
}
else {
$('.fb_chk').each(function() {
$(this).prop("checked", false);
})
}
})