1
我是新来reactjs并试图打印输入字段的更新值。我第一次尝试的是:ReactJs即时打印值
var App = React.createClass({
render() {
return <div>
<h1>Hello, {this.props.name}</h1>
<input type="text" onKeyUp={this.handleChange} />
<p>{this.handleChange}</p>
</div>;
},
handleChange: function(event) {
return event.target.value;
}
});
App = React.createFactory(App);
React.render(
<App name="World" />,
document.getElementById('mount-point'));
但我不明白为什么它不工作。比我试过这样:CodePen也许有人可以帮我即刻打印在<p>
元素的输入字段的值
您需要将更改的值存储到您的'handleChange'内的状态(例如'this.setState({myInputValue:event.target.value});')。然后你可以像这样“打印”你的'p'中的值:'
{this.state.myInputValue}
'。 – ctrlplusb强烈建议您阅读文档和教程。 https://facebook.github.io/react/docs/thinking-in-react.html否则,你只是在猜测API。 – ctrlplusb
相关文档:https://facebook.github.io/react/docs/forms.html – ctrlplusb