1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title>
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin ></script> <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin ></script> <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script> </head> <body> <div id="root"></div> <script type="text/babel"> class Login extends React.Component { constructor(props) { super(props); this.login = this.login.bind(this); this.check = this.check.bind(this); this.state = { userName: 'admin', passWord: 'admin', }; } login() { if ( this.refs.user.value === this.state.userName && this.refs.pwd.value === this.state.passWord ) { alert('success'); } else { alert('failed'); } } check() { if (this.refs.user.value.length > 10) alert('more than 10 characters, checkout again.'); } render() { var loginStyle = { width: 400, height: 250, background: '#FFF', margin: '200px auto', position: 'relative', }; var hStyle = { position: 'absolute', left: 95, top: -40, padding: 0, margin: 50, }; var pStyle = { textAlign: 'center', }; var userStyle = { width: 200, height: 30, border: 'solid #ccc 1px', borderRadius: 3, paddingLeft: 32, marginTop: 50, }; var pwdStyle = { width: 200, height: 30, border: 'solid #ccc 1px', borderRadius: 3, paddingLeft: 32, marginTop: 5, }; var buttonStyle = { width: 232, height: 30, background: '#E9E9E9', border: 'solid #ccc 1px', borderRadius: 3, textAlign: 'center', }; return ( <div style={loginStyle}> <h1 style={hStyle}>LOGIN</h1> <div> <p style={pStyle}> <input type="text" style={userStyle} placeholder="USERNAME" ref="user" onChange={this.check} /> </p> <p style={pStyle}> <input type="password" style={pwdStyle} placeholder="PASSWORD" ref="pwd" /> </p> <p style={pStyle}> <button style={buttonStyle} onClick={this.login}> LOGIN! </button> </p> </div> </div> ); } } ReactDOM.render(<Login />, document.getElementById('root')); </script> </body> </html>
|