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

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

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

图片转代码服务由CSDN问答提供 功能建议

如果选中单选按钮,如何在html中启用按钮。 这是动态完成的,就像单选按钮取消选中一样,按钮也应该自动禁用。 是否有任何可能的方法来使用javascript或Jquery ..代码应该在PHP

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

1条回答 默认 最新

  • 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.

    打赏 评论

相关推荐 更多相似问题