<small id='kPaNj'></small><noframes id='kPaNj'>

<i id='kPaNj'><tr id='kPaNj'><dt id='kPaNj'><q id='kPaNj'><span id='kPaNj'><b id='kPaNj'><form id='kPaNj'><ins id='kPaNj'></ins><ul id='kPaNj'></ul><sub id='kPaNj'></sub></form><legend id='kPaNj'></legend><bdo id='kPaNj'><pre id='kPaNj'><center id='kPaNj'></center></pre></bdo></b><th id='kPaNj'></th></span></q></dt></tr></i><div id='kPaNj'><tfoot id='kPaNj'></tfoot><dl id='kPaNj'><fieldset id='kPaNj'></fieldset></dl></div>

        <tfoot id='kPaNj'></tfoot>
        • <bdo id='kPaNj'></bdo><ul id='kPaNj'></ul>

        <legend id='kPaNj'><style id='kPaNj'><dir id='kPaNj'><q id='kPaNj'></q></dir></style></legend>

        验证 HTML 中的复选框

        时间:2023-10-20
      1. <small id='hOysO'></small><noframes id='hOysO'>

          <tfoot id='hOysO'></tfoot>

          <i id='hOysO'><tr id='hOysO'><dt id='hOysO'><q id='hOysO'><span id='hOysO'><b id='hOysO'><form id='hOysO'><ins id='hOysO'></ins><ul id='hOysO'></ul><sub id='hOysO'></sub></form><legend id='hOysO'></legend><bdo id='hOysO'><pre id='hOysO'><center id='hOysO'></center></pre></bdo></b><th id='hOysO'></th></span></q></dt></tr></i><div id='hOysO'><tfoot id='hOysO'></tfoot><dl id='hOysO'><fieldset id='hOysO'></fieldset></dl></div>

          <legend id='hOysO'><style id='hOysO'><dir id='hOysO'><q id='hOysO'></q></dir></style></legend>
                <tbody id='hOysO'></tbody>
                  <bdo id='hOysO'></bdo><ul id='hOysO'></ul>
                • 本文介绍了验证 HTML 中的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个表格,有 4 个选项(可能是复选框或单选).

                  I have a form there are 4 options (they may be checkbox or radio).

                  我想选择多个选项,但必须选择一个.

                  I want to select multiple options but one is compulsory.

                  我知道这在 JS/jQuery 中是可能的,但我想要一个基于 HTML/CSS 的解决方案.

                  I know it is possible in JS/jQuery but I want a HTML/CSS based solution.

                  推荐答案

                  为了能够检查多个输入,它们必须是复选框.(它们可能是具有不同名称的单选按钮,但一旦选中,您将无法取消选中它们.)

                  To be able to check multiple inputs, they must be checkboxes. (They could be radio buttons with different names, but you wouldn't be able to uncheck them once checked.)

                  因此,请使用复选框,并仅在选中时显示提交按钮,使用 通用兄弟选择器 (~):

                  So use checkboxes, and show the Submit button only if any are checked, using the general sibling selector (~):

                  input[type="Submit"] {
                    display: none;
                  }
                  
                  input:checked ~ input[type="Submit"] {
                    display: inline;
                  }

                  <input id="c1" type="checkbox"><label for="c1">First</label><br>
                  <input id="c2" type="checkbox"><label for="c2">Second</label><br>
                  <input id="c3" type="checkbox"><label for="c3">Third</label><br>
                  <input id="c4" type="checkbox"><label for="c4">Fourth</label><br>
                  <input type="Submit">

                  <小时>如果您希望显示禁用的提交按钮,请添加第二个禁用的按钮.


                  If you want the appearance of a disabled submit button, add a second button that is disabled.

                  当没有点击输入时,只显示禁用的提交按钮.单击一个或多个输入时,仅显示启用的提交按钮:

                  When no input is clicked, show the disabled submit button only. When one or more inputs are clicked, show the enabled submit button only:

                  input[type="Submit"]:not([disabled]) {
                    display: none;
                  }
                  
                  input:checked ~ input[type="Submit"]:not([disabled]) {
                    display: inline;
                  }
                  
                  input:checked ~ input[disabled] {
                    display: none;
                  }

                  <input id="c1" type="checkbox"><label for="c1">First</label><br>
                  <input id="c2" type="checkbox"><label for="c2">Second</label><br>
                  <input id="c3" type="checkbox"><label for="c3">Third</label><br>
                  <input id="c4" type="checkbox"><label for="c4">Fourth</label><br>
                  
                  <input type="Submit" disabled>
                  <input type="Submit">

                  这篇关于验证 HTML 中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用 CSS 为 HTML 表单中的单选按钮制作多行、垂直和水平对齐的标签? 下一篇:单选按钮在 Chrome 中显示不需要的白色背景.火狐没问题

                  相关文章

                    <bdo id='p2tUx'></bdo><ul id='p2tUx'></ul>
                  <tfoot id='p2tUx'></tfoot>
                • <small id='p2tUx'></small><noframes id='p2tUx'>

                    <legend id='p2tUx'><style id='p2tUx'><dir id='p2tUx'><q id='p2tUx'></q></dir></style></legend>
                      <i id='p2tUx'><tr id='p2tUx'><dt id='p2tUx'><q id='p2tUx'><span id='p2tUx'><b id='p2tUx'><form id='p2tUx'><ins id='p2tUx'></ins><ul id='p2tUx'></ul><sub id='p2tUx'></sub></form><legend id='p2tUx'></legend><bdo id='p2tUx'><pre id='p2tUx'><center id='p2tUx'></center></pre></bdo></b><th id='p2tUx'></th></span></q></dt></tr></i><div id='p2tUx'><tfoot id='p2tUx'></tfoot><dl id='p2tUx'><fieldset id='p2tUx'></fieldset></dl></div>