• <bdo id='hsoPz'></bdo><ul id='hsoPz'></ul>
      <tfoot id='hsoPz'></tfoot>
      1. <small id='hsoPz'></small><noframes id='hsoPz'>

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

        如何在 React 中使用单选按钮?

        How do I use radio buttons in React?(如何在 React 中使用单选按钮?)
      3. <legend id='XqTes'><style id='XqTes'><dir id='XqTes'><q id='XqTes'></q></dir></style></legend>

            <tbody id='XqTes'></tbody>
          <tfoot id='XqTes'></tfoot>

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

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

                  本文介绍了如何在 React 中使用单选按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在制作一个表格,我需要一个无线电输入.如何在 onSubmit 函数中获取选中的无线电输入,正确的方法是什么?

                  I'm making a form, and I was in need of a radio input. How do I get the checked radio input in a onSubmit-function, what is the correct way?

                  这是我的代码,我的 myRadioInput 变量在我提交时包含选项 A 或选项 B:

                  This is my code, I myRadioInput-variable to contain either Option A or Option B when I submit:

                  React.createClass({
                      handleSubmit: function() {
                          e.preventDefault();
                          var myTextInput = this.refs.myTextInput.getDOMNode().value.trim();
                          var myRadioInput = "How ?";
                      },
                      render: function() {
                          return (
                              <form onSubmit={this.handleSubmit}>
                                  <input type="text" ref="myTextInput" />
                                  <label>
                                      <span>Option A</span>
                                      <input type="radio" name="myRadioInput" value="Option A"/>
                                  </label>
                                  <label>
                                      <span>Option B</span>
                                      <input type="radio" name="myRadioInput" value="Option B"/>
                                  </label>
                                  <input type="submit" value="Submit this"/>
                              </form>
                          )
                      }
                  });
                  

                  推荐答案

                  您不应该使用 refs 来访问 DOM 节点并检查它们的值.相反,您应该将输入值链接到组件状态的属性.

                  You shouldn't use refs to get access to DOM nodes and inspect their value. Instead you should link the inputs value to a property on the component state.

                  这里有一些示例:https://facebook.github.io/react/docs/two-way-binding-helpers.html

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

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

                  相关文档推荐

                  在开发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='uUbPO'><style id='uUbPO'><dir id='uUbPO'><q id='uUbPO'></q></dir></style></legend>

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

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

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

                            <tbody id='uUbPO'></tbody>
                        1. <tfoot id='uUbPO'></tfoot>