反应:输入字段不接收输入

时间:2016-05-07 10:46:51

标签: reactjs

我尝试输入表单输入字段,但它不起作用。目前它处于只读模式,我不知道为什么。这是组件:

import React from 'react';

export default class SearchBar extends React.Component {

  constructor(props) {
    super(props);
    this.state = { term: ''};
    this.onInputChange = this.onInputChange.bind(this);
  }

  onInputChange(event) {
    console.log(event.target.value);
    this.setState({ term: event.target.value});
  }

  render() {
    return (
    <form className="input-group">
      <input
        placeholder="Give a five day forecast"
        className="form-control"
        value={this.state.term}
        onChange={this.noInputChange}
        />
      <span className="input-group-btn">
        <button type="submit" className="btn btn-secondary"> Submit</button>
      </span>
    </form>
  )
  }
}

1 个答案:

答案 0 :(得分:1)

onChange={this.noInputChange}

应该是

onChange={this.onInputChange}