【发布时间】:2017-07-16 16:17:57
【问题描述】:
代码:
class RegistrationPage extends Component {
constructor() {
super();
this.state = {
style : {
borderBottomColor : ""
}
}
this.handleOnClick = this.handleOnClick.bind(this);
}
handleOnFocus() {
this.setState({
style : {
borderBottomColor : "orange"
}
})
}
render() {
return (
<div id="reg_div">
<h3 id="heading">Sign Up</h3>
<form>
<label htmlFor="userName">ENTER USERNAME</label>
<br />
<div className="userInputBox" style={this.state.style}>
<input type="text" name="userName" className="inputStyle" placeholder="Enter Here" onFocus={this.handleOnFocus} />
</div>
<br />
<label htmlFor="key">ENTER KEY</label>
<br />
<div className="userInputBox" style={this.state.style}>
<input type="password" name="key" className="inputStyle" placeholder="Enter Here" onFocus={this.handleOnFocus} />
</div>
<button id="sign_up">REGISTER</button>
</form>
<div id="btn">
<button id="sign_in_page">I already have an account</button>
</div>
</div>
)
}
}
问题: 我有两个输入字段,一个用于用户名,另一个用于键。每个都有其特定的父 div。当我关注任何输入字段时,它会更改两个 div 的状态,而我想更改输入字段所关注的特定 div 的状态。
【问题讨论】:
-
每个输入都有状态,passwordInputStyle 和 usernameInputStyle
标签: reactjs ecmascript-6