我正在学习ReactJS,我想了解如何使用简单的onclick事件获取ReactJS中的输入文本值.虽然我能够获得文本输入的参数,但我还是遵循了教程.但不知何故,我无法得到它的价值.
var MyComponent = React.createClass({
handleClick: function() {
if (this.refs.myInput !== null) {
var input = this.refs.myInput;
var inputValue = input.value;
alert("Input is", inputValue);
}
},
render: function() {
return (
<div>
<input type="text" ref="myInput" />
<input
type="button"
value="Alert the text input"
onClick={this.handleClick}
/>
</div>
);
}
});
ReactDOM.render(
<MyComponent />,
document.getElementById('container')
);
这里是同样的JSFIDLE:jsfiddle link