jquery - 将字段设为只读 - 复选框 - jQuery

标签 jquery html checkbox

我有这个复选框:

<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/

相关文章:

javascript - 在表单提交之外调用此函数

javascript - 在 jQuery 函数中声明多个 div 选择器

java - list 文件中需要哪些权限才能让小程序通过 Javascript 进行通信

javascript - 切换多个复选框

javascript - 如果我选择第一个复选框然后禁用所有剩余的复选框

wpf - 如何将命令绑定(bind)到复选框

jquery - 如何防止mooTools和Prototype之间的冲突

javascript - 动态更改 URL 结构——后退/前进

javascript - 如何让页脚从 DOM 的第 3 页开始

html - Twitter Bootstrap 页面在 Chrome 中闲置一段时间后丢失样式