1、问题背景
利用React实现生成input输入框,并在输入框中赋值
2、实现源码
<!DOCTYPE html> <html> <head> <Meta charset="UTF-8"> <title>React生成表单input</title> <script type="text/javascript" src="../js/react.js" ></script> <script type="text/javascript" src="../js/react-dom.js" ></script> <script type="text/javascript" src="../js/browser.min.js" ></script> <script type="text/babel"> var Input = React.createClass({ getInitialState:function(){ return {value:'请输入用户名!'}; },inputChange:function(event){ this.setState({value:event.target.value}); },render:function(){ var value = this.state.value; return ( <input type="text" value={value} onchange={this.inputChange} /> ); } }); ReactDOM.render( <Input />,document.body ); </script> </head> <body> </body> </html>
3、实现结果
原文链接:https://www.f2er.com/react/305789.html