Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将onChange与React一起使用时,不会注册空格_Javascript_Reactjs_Onchange - Fatal编程技术网

Javascript 将onChange与React一起使用时,不会注册空格

Javascript 将onChange与React一起使用时,不会注册空格,javascript,reactjs,onchange,Javascript,Reactjs,Onchange,我正试图使用此处描述的onChange方法保存用户的输入: 我的输入有以下代码行: <input type="text" onChange={this.changeTitle} ref="title" value={this.props.quiz ? this.getTitle() : ''}></input> 但是,当我在按下空格键后调用this.refs.title.value时,空格未注册。我可以注册这个空间吗 像这样的东西 var ChangeV

我正试图使用此处描述的onChange方法保存用户的输入:

我的输入有以下代码行:

      <input type="text" onChange={this.changeTitle} ref="title" value={this.props.quiz ? this.getTitle() : ''}></input>

但是,当我在按下空格键后调用
this.refs.title.value
时,空格未注册。我可以注册这个空间吗

像这样的东西

var ChangeValue = React.createClass({

    getInitialState() {
      return { currentValue: '' };
    },

    onValueChange: function (evnt) {
      this.setState({ currentValue: evnt.target.value });
    },

    render: function() {
        return (
          <div>
             <input type="text" onChange={this.onValueChange} />
             <p>
               Current value is: <b>{this.state.currentValue}</b>
             </p>
          </div>
        );
    }
});

React.render(<ChangeValue />, document.body);
var ChangeValue=React.createClass({
getInitialState(){
返回{currentValue:''};
},
onValueChange:函数(evnt){
this.setState({currentValue:evnt.target.value});
},
render:function(){
返回(

当前值为:{this.state.currentValue}

); } }); React.render(,document.body);
只需更改onValueChange方法即可完成所需操作。
实时示例:

输入应该注册空格/应该触发
this。如果按空格键,则更改title
。如果没有进一步的代码,很难说会发生什么。在任何情况下,将输入的值置于某种状态,并将
value={this.props.quick?this.getTitle():''}
替换为类似
value={this.state.value}