How to disable/enable input field on click with jQuery

后端 未结 7 785
慢半拍i
慢半拍i 2020-12-31 13:36

How to properly enable/disable input field on click with jQuery?

I was experimenting with:

$(\"#FullName\").removeAttr(\'disabled\');
7条回答
  •  甜味超标
    2020-12-31 14:33

    $('#checkbox-id').click(function()
    {
        //If checkbox is checked then disable or enable input
        if ($(this).is(':checked'))
        {
            $("#to-enable-input").removeAttr("disabled"); 
            $("#to-disable-input").attr("disabled","disabled");
        }
        //If checkbox is unchecked then disable or enable input
        else
        {
            $("#to-enable-input").removeAttr("disabled"); 
            $("#to-disable-input").attr("disabled","disabled");
        }
    });
    

提交回复
热议问题