duan5731
duan5731
2018-05-22 16:11
浏览 320

如果选中或取消选中单选按钮,则启用或禁用按钮

How to Enable a button in html if the radio button is checked. this is to be done dynamically as if the radio button gets unchecked the button should also get disabled automatically. is there any possible way to do this using javascript or Jquery..code should should be in php

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dtlhy0771
    dtlhy0771 2018-05-22 16:14
    已采纳

    You can't uncheck a radio button, but if you want to do it on a checkbox, here is a suggestion using jquery:

       $("#checkBoxID").on("change", function(e) {
        $("#buttonID").prop("disabled",!$("#checkBoxID").is(":checked"));
      });
    

    This will set the disabled attribute on the button to the opposite of the checked attribute.

    •Box Checked? Disabled Attribute on button set to false

    •Box unchecked? Disabled attribute on button set to true

    Updates dynamically as the checkbox is selected.

    -- edit --

    Here is a link to a JSFiddle of this working as described and requested.

    点赞 评论

相关推荐