<tfoot id='SV1oU'></tfoot>

    1. <legend id='SV1oU'><style id='SV1oU'><dir id='SV1oU'><q id='SV1oU'></q></dir></style></legend>
      • <bdo id='SV1oU'></bdo><ul id='SV1oU'></ul>

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

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

        JavaScript 读取 IE 和 FireFox 中的单选按钮值

        JavaScript read radio button value in IE and FireFox(JavaScript 读取 IE 和 FireFox 中的单选按钮值)
          <tbody id='MGtKR'></tbody>

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

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

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

                  <tfoot id='MGtKR'></tfoot>
                1. 本文介绍了JavaScript 读取 IE 和 FireFox 中的单选按钮值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个使用 JavaScript 构建 POST 语句的简单 Web 表单.在 Chrome 中,我可以使用简单的一行代码...

                  I have a simple web form that uses JavaScript for building a POST statement. In Chrome, I can use a simple line of code...

                  var form = document.forms['myForm'];
                  var env = form.env.value;
                  

                  表单本身看起来像这样......

                  The form itself looks like this...

                  <form name="myForm" action='JavaScript:xmlhttpPost("/path/to/some/pythoncode.py")'>
                      <input type="radio" name="env" id="env" value="inside">Inside
                      <input type="radio" name="env" id="env" value="outside" checked="checked">Outside
                      <input type="radio" name="env" id="env" value="both">Both
                      <input type="radio" name="env" id="env" value="neither">Neither
                  

                  我在表单上有一些文本框,我可以使用相同的技术来查找值(var name = form.fname.value<input type="text" name="fname" id="fname">但是,当我提交表单并构建帖子时,单选按钮的值始终未定义.它在 Chrome 中运行良好,但在 IE 或 FireFox 中没有.

                  I have some text boxes on the form that I can use the same technique to find the value ( var name = form.fname.value with a <input type="text" name="fname" id="fname"> However, when I submit the form and build my post, the value for the radio buttons is always undefined. It works fine in Chrome, but nothing in IE or FireFox.

                  我尝试了 var env = document.getElementById('env').value,但由于某种原因,无论我选择什么,它总是默认为第一个值(内部).该方法在使用 Chrome 时也不会返回值.

                  I tried var env = document.getElementById('env').value, but for some reason that always defaults to the first value (inside) no matter what I select. That method also does not return a value when using Chrome.

                  在读取 FF 或 IE 中的无线电输入的检查值时,我是否缺少某些东西?

                  Is there something I'm missing for reading the checked value of a radio input in FF or IE?

                  推荐答案

                  试试这个

                  function getValueFromRadioButton(name) {
                     //Get all elements with the name
                     var buttons = document.getElementsByName(name);
                     for(var i = 0; i < buttons.length; i++) {
                        //Check if button is checked
                        var button = buttons[i];
                        if(button.checked) {
                           //Return value
                           return button.value;
                        }
                     }
                     //No radio button is selected. 
                     return null;
                  }
                  

                  ID 是唯一的,因此您不应为多个项目使用相同的 ID.如果您使用此功能,您可以删除所有单选按钮 ID.

                  IDs are unique so you should not use the same ID for multiple items. You can remove the all the radio button IDs if you use this function.

                  这篇关于JavaScript 读取 IE 和 FireFox 中的单选按钮值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  keeping radio buttons checked after form submit(表单提交后保持选中单选按钮)
                  Bootstrap radio button quot;checkedquot; flag(Bootstrap 单选按钮“已选中旗帜)
                  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 自动选择特定的单选按钮?)

                      <legend id='dW3Lq'><style id='dW3Lq'><dir id='dW3Lq'><q id='dW3Lq'></q></dir></style></legend>
                      <tfoot id='dW3Lq'></tfoot>
                    1. <small id='dW3Lq'></small><noframes id='dW3Lq'>

                      • <bdo id='dW3Lq'></bdo><ul id='dW3Lq'></ul>

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

                            <tbody id='dW3Lq'></tbody>