jquery enable/disable text box based on radiobutton

后端 未结 2 1870
日久生厌
日久生厌 2021-02-19 16:13

In my page (jsp) i have a radiobutton group and a textbox (which is disabled initially).

  • Whenever the user clicks on a radio button the textbox should be enabled <
2条回答
  •  北海茫月
    2021-02-19 16:25

    Always disable it (for every radio button), then re-enable it if the radio button is the one that enables the textbox. Unless the user is on a machine built in 1980, it will be so fast, not one will ever know.

    $('radio').click(function() { 
        $("#otherDevText").prop("disabled",true);
        if($(this).attr('id') == 'enable_textbox') {
            $("#otherDevText").prop("disabled",false);
        }
    });
    

    Alternatively, if there are multiple radio buttons that will enable the textbox:

    $('input:radio').click(function() { 
      $("#otherDevText").prop("disabled",true);
      if($(this).hasClass('enable_tb')) {
          $("#otherDevText").prop("disabled",false);
      }
    });
    
    
    dev1
    dev2
    enable

    Make sense?

提交回复
热议问题