<span className="search2-icon" ref="searchIcon"></span>
<input className="search2-input"
ref="searchInput"
type="text"
onFocus={this.handleFocus.bind(this)}
onBlur={this.handleBlur.bind(this)}/>
注意要使用原生js的DOM操作:
handleFocus(){
ReactDOM.findDOMNode(this.refs.searchIcon).setAttribute("style","display:none");
}
handleBlur() {
if(ReactDOM.findDOMNode(this.refs.searchInput).value == "")
ReactDOM.findDOMNode(this.refs.searchIcon).setAttribute("style","display:block");
}