繁体   English   中英

选择某些单选按钮时切换显示并启用文本文件

[英]Toggle Show and Enable Textfiled When Certain Radio Button is Selected

我希望能够在每次选择“其他”单选按钮时显示并启用一个输入字段(最初是隐藏和禁用的),并且在选择其他单选按钮时也将隐藏并禁用一个输入字段。 我已经获得了该脚本来适当地显示和隐藏文本字段,但是我想知道如何才能启用和禁用它

$('input[name="x_description"]').bind('change',function(){
    var showOrHide = ($(this).val() == "Other") ? true : false;
    $('#other_program_text').toggle(showOrHide);  
});

我知道这是显示字段并启用文本字段的方法,但无法弄清楚如何将它们组合在一起,

$(this).show().prop('disabled', false);

预先感谢,丹

$('input[name="x_description"]').bind('change',function(){
    if ( showOrHide == true ) {
        $('#other_program_text').show().prop('disabled',false);
    } else if ( showOrHide == false ) {
        $('#other_program_text').hide().prop('disabled',true);
    }
});

您想使用$(this).attr()函数在HTML元素上设置属性。 使用一个参数将读取传递的参数,使用两个参数将其设置。

像$(this).attr(“ enabled”,true)

您可以使用“点击”方法

 $('input[name="x_description"]').click(function() {
       if($('#radio_button').is(':checked')) { 
           alert("it's checked"); //do your stuff
        }
 });

如果您的内容是动态生成的,则使用“实时”方法

 $('input[name="x_description"]').live('click',function() {
           if($('#radio_button').is(':checked')) { 
               alert("it's checked"); //do your stuff
            }
 });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM