我有这个复选框:
<input type="checkbox" name="suspended" id="s" value="<?php echo $udata['suspended']; ?>" <?php echo $suspended; ?>>
还有这个文本区域:
<textarea name="suspendreason" id="sr" style="height:60px" class="field"><?php echo $udata['suspendreason']; ?></textarea>
我的问题是,当#s 复选框未选中时,我如何才能将文本区域设置为只读?
最佳答案
根据你的要求,像这样:
$(document).ready(function(){
if($('#s:checked').length){
$('#sr').attr('readonly',true); // On Load, should it be read only?
}
$('#s').change(function(){
if($('#s:checked').length){
$('#sr').attr('readonly',true); //If checked - Read only
}else{
$('#sr').attr('readonly',false);//Not Checked - Normal
}
});
});
关于jquery - 将字段设为只读 - 复选框 - jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7419383/