【问题标题】:I need to disable ONLY the checkbox that is checked after i submit the form:我只需要禁用提交表单后选中的复选框:
【发布时间】:2020-07-25 13:43:07
【问题描述】:

这是我的 HTML 代码:

其实我有更多的复选框被设计成按钮来选择房间(由复选框表示),所以所有这些都被选中非常烦人。

$("form").submit(function() {
  $('.seat input:checkbox').prop("disabled", true);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


<form name="qwer" action="/" method="post">
  <ol class="block1">
    <li class="row row--1">
      <ol class="seats" type="A">
        <li class="seat">
          <input type="checkbox" id="1A" />
          <label for="1A">1A</label>
        </li>
        <li class="seat">
          <input type="checkbox" id="1B" />
          <label for="1B">1B</label>
        </li>
        <li class="seat">
          <input type="checkbox" id="1C" />
          <label for="1C">1C</label>
        </li>
        <input type="submit" value="Register" />
</form>

在我选中选中的复选框并提交表单后,所有其他复选框也会被禁用。

【问题讨论】:

    标签: javascript html jquery node.js express


    【解决方案1】:

    您还必须添加 :checked 才能仅禁用选中的复选框。

    $("form").submit(function() {
      $('.seat input:checkbox:checked').prop("disabled", true); //Change here
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    
    
    <form name="qwer" action="/" method="post">
      <ol class="block1">
        <li class="row row--1">
          <ol class="seats" type="A">
            <li class="seat">
              <input type="checkbox" id="1A" />
              <label for="1A">1A</label>
            </li>
            <li class="seat">
              <input type="checkbox" id="1B" />
              <label for="1B">1B</label>
            </li>
            <li class="seat">
              <input type="checkbox" id="1C" />
              <label for="1C">1C</label>
            </li>
            <input type="submit" value="Register" />
    </form>

    【讨论】:

    • @Yeshu62 如果你觉得这个答案对你的问题有帮助,你可以接受这个答案,让其他人也能受益。见How to accept an answer
    猜你喜欢
    • 2013-06-03
    • 1970-01-01
    • 2021-10-29
    • 2016-10-03
    • 2013-08-10
    • 2015-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多