我试图在这里添加一个只读属性。你能帮我解决这里的代码吗?如果选中了这个框,我的平均行将是只读的?
<input type="text" name="average[]" class="average"
id="average_<?php echo $row['student_no']; ?>" value="<?php echo
$row['average_pts']; ?>" >
<input type="checkbox" name="disable[<?php echo $row['student_no']; ?>]" id="disable" value="1" class="disable" <?php if ($row['disable_comp']=='1') { echo "checked=\"checked\""; } ?>>
$(".disable").change(function() {
var val = $(this).val();
if ($(this).is(':checked')) {
var checked = $('input[type=checkbox]').is(':checked');
$("input").unbind('keyup', computeValues);
var checked=$("#able").is(':checked');
}else{
$("input").bind('keyup', computeValues).trigger('keyup');
$("#average").prop('readonly');
}
});发布于 2013-04-10 11:04:37
假设条件是正确的,您只需要使用attr函数:
$('#able').attr('readonly', true);发布于 2013-04-10 11:09:50
$(".disable").on('change', function() {
if ( this.checked ) $("#able").prop('readonly', true);
});发布于 2013-04-10 13:26:15
$("#average").attr("readonly",true);$("#average").prop("readonly",true);
尝试使用这两个属性,因为某些时候会设置attr,但在功能上永远不会起作用,所以我们需要同时使用它们……(在页面加载时,我们必须使用attr。)请找到Attributes vs. Properties.
https://stackoverflow.com/questions/15916177
复制相似问题