<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 中的单选按钮值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)

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