<tfoot id='xAX1F'></tfoot>

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

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

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

        如何获取选定单选按钮的值?

        时间:2023-10-21
          <tbody id='wqHTV'></tbody>

          <tfoot id='wqHTV'></tfoot>

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

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

          1. <legend id='wqHTV'><style id='wqHTV'><dir id='wqHTV'><q id='wqHTV'></q></dir></style></legend>
            • <bdo id='wqHTV'></bdo><ul id='wqHTV'></ul>
                  本文介绍了如何获取选定单选按钮的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想从一组单选按钮中获取选定的值.

                  I want to get the selected value from a group of radio buttons.

                  这是我的 HTML:

                  <div id="rates">
                    <input type="radio" id="r1" name="rate" value="Fixed Rate"> Fixed Rate
                    <input type="radio" id="r2" name="rate" value="Variable Rate"> Variable Rate
                    <input type="radio" id="r3" name="rate" value="Multi Rate" checked="checked"> Multi Rate  
                  </div>
                  

                  这是我的 js:

                  var rates = document.getElementById('rates').value;
                  var rate_value;
                  if(rates =='Fixed Rate'){
                      rate_value = document.getElementById('r1').value;
                      
                  }else if(rates =='Variable Rate'){
                      rate_value = document.getElementById('r2').value;
                      
                  }else if(rates =='Multi Rate'){
                      rate_value = document.getElementById('r3').value;
                  }  
                  
                  document.getElementById('results').innerHTML = rate_value;
                  

                  我一直不确定.

                  推荐答案

                  var rates = document.getElementById('rates').value;
                  

                  rates 元素是一个 div,所以它没有值.这可能是 undefined 的来源.

                  The rates element is a div, so it won't have a value. This is probably where the undefined is coming from.

                  checked 属性会告诉你元素是否被选中:

                  The checked property will tell you whether the element is selected:

                  if (document.getElementById('r1').checked) {
                    rate_value = document.getElementById('r1').value;
                  }
                  

                  或者

                  $("input[type='radio'][name='rate']:checked").val();
                  

                  这篇关于如何获取选定单选按钮的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何检查是否使用 JavaScript 选择了单选按钮? 下一篇:如何使用js获取选定的单选按钮值

                  相关文章

                  • <bdo id='SsfH9'></bdo><ul id='SsfH9'></ul>
                  <legend id='SsfH9'><style id='SsfH9'><dir id='SsfH9'><q id='SsfH9'></q></dir></style></legend>

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

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