<bdo id='mkj0n'></bdo><ul id='mkj0n'></ul>

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

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

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

        <tfoot id='mkj0n'></tfoot>
      2. 如何检查是否使用 JavaScript 选择了单选按钮?

        How can I check whether a radio button is selected with JavaScript?(如何检查是否使用 JavaScript 选择了单选按钮?)

        <legend id='G4jvG'><style id='G4jvG'><dir id='G4jvG'><q id='G4jvG'></q></dir></style></legend>
        • <small id='G4jvG'></small><noframes id='G4jvG'>

            • <i id='G4jvG'><tr id='G4jvG'><dt id='G4jvG'><q id='G4jvG'><span id='G4jvG'><b id='G4jvG'><form id='G4jvG'><ins id='G4jvG'></ins><ul id='G4jvG'></ul><sub id='G4jvG'></sub></form><legend id='G4jvG'></legend><bdo id='G4jvG'><pre id='G4jvG'><center id='G4jvG'></center></pre></bdo></b><th id='G4jvG'></th></span></q></dt></tr></i><div id='G4jvG'><tfoot id='G4jvG'></tfoot><dl id='G4jvG'><fieldset id='G4jvG'></fieldset></dl></div>
                <tbody id='G4jvG'></tbody>
              1. <tfoot id='G4jvG'></tfoot>
                  <bdo id='G4jvG'></bdo><ul id='G4jvG'></ul>
                  本文介绍了如何检查是否使用 JavaScript 选择了单选按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 HTML 表单中有两个单选按钮.当其中一个字段为空时,会出现一个对话框.如何检查单选按钮是否被选中?

                  I have two radio buttons within an HTML form. A dialog box appears when one of the fields is null. How can I check whether a radio button is selected?

                  推荐答案

                  假设你有这样的 HTML

                  Let's pretend you have HTML like this

                  <input type="radio" name="gender" id="gender_Male" value="Male" />
                  <input type="radio" name="gender" id="gender_Female" value="Female" />
                  

                  对于客户端验证,这里有一些 Javascript 来检查选择了哪一个:

                  For client-side validation, here's some Javascript to check which one is selected:

                  if(document.getElementById('gender_Male').checked) {
                    //Male radio button is checked
                  }else if(document.getElementById('gender_Female').checked) {
                    //Female radio button is checked
                  }
                  

                  根据您的标记的确切性质,上述内容可能会更有效,但这应该足以让您开始.

                  The above could be made more efficient depending on the exact nature of your markup but that should be enough to get you started.

                  如果您只是想查看页面上的any单选按钮是否被选中anywhere,PrototypeJS 让它变得非常简单.

                  If you're just looking to see if any radio button is selected anywhere on the page, PrototypeJS makes it very easy.

                  如果在页面某处至少选择了一个单选按钮,此函数将返回 true.同样,这可能需要根据您的特定 HTML 进行调整.

                  Here's a function that will return true if at least one radio button is selected somewhere on the page. Again, this might need to be tweaked depending on your specific HTML.

                  function atLeastOneRadio() {
                      return ($('input[type=radio]:checked').size() > 0);
                  }
                  

                  <小时>

                  对于服务器端验证(请记住,您不能完全依赖 Javascript 进行验证!),这取决于您选择的语言,但您只需检查 性别请求字符串的值.


                  For server-side validation (remember, you can't depend entirely on Javascript for validation!), it would depend on your language of choice, but you'd but checking the gender value of the request string.

                  这篇关于如何检查是否使用 JavaScript 选择了单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  keeping radio buttons checked after form submit(表单提交后保持选中单选按钮)
                  Styling radio button - not work in IE and Firefox(样式单选按钮 - 在 IE 和 Firefox 中不起作用)
                  Toggle HTML radio button by clicking its label(通过单击标签来切换 HTML 单选按钮)
                  Javascript how to change radio button label text?(Javascript如何更改单选按钮标签文本?)
                  JavaScript radio button confirmation(JavaScript 单选按钮确认)
                  How can I automatically select specific radio buttons with Greasemonkey?(如何使用 Greasemonkey 自动选择特定的单选按钮?)
                    <tbody id='yEKhK'></tbody>

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

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