使用React實作類別似快遞單號查詢效果

來源:互聯網
上載者:User

標籤:

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <meta name="Keywords" content="關鍵詞一,關鍵詞二">    <meta name="Description" content="網站描述內容">    <meta name="Author" content="劉豔">    <title></title></head><body>    <div id = "example"></div></body></html><script src = "build/jquery-1.11.2.min.js"></script><script src = "build/react.js"></script><script src = "build/react-dom.js"></script><script src = "build/browser.min.js"></script><script type="text/babel">    var MyComponent = React.createClass({        handKeyUp: function () {            this.refs.clone.innerHTML = this.refs.target.value;        },        render: function () {            return (<div>                        <div ref = "clone" style = {{height:40+‘px‘,fontSize:28+‘px‘}}></div>                        <input type = "text"  ref = "target" onKeyUp = {this.handKeyUp}></input>                    </div>);        }    });    ReactDOM.render(<MyComponent></MyComponent>,document.querySelector("#example"));</script>

實現效果如下:

CSS美化略過,因為主要是學習React使用。
另一種更為簡便的寫法如下,充分利用react組件的state:

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <meta name="Keywords" content="關鍵詞一,關鍵詞二">    <meta name="Description" content="網站描述內容">    <meta name="Author" content="劉豔">    <title></title></head><body><div id = "example"></div></body></html><script src="build/react.js"></script><script src="build/react-dom.min.js"></script><script src="build/browser.min.js"></script><script type="text/babel">    var Input = React.createClass({        getInitialState: function(){            return {value: "Hello"};        },        handleChange: function (event) {            this.setState({value: event.target.value});        },        render: function(){            var value = this.state.value;            return (                <div>                    <p>{value}</p>                    <input type = "text" value = {value} onChange = {this.handleChange} />                </div>            );        }    });    ReactDOM.render(        <Input />,        document.querySelector("#example")    )</script>

使用React實作類別似快遞單號查詢效果

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.