onFocus 和 onBlur 不会在反应中呈现
onFocus and onBlur does not render in react
我有以下代码
<ElementsBasket
name="nextActionDate"
data={this.props.newLead.get("actions").get("nextActionDate")}
>
<div className="form-group">
<span className="glyphicon glyphicon-calendar">Calendar </span>
<span className="glyphicon glyphicon-triangle-bottom"></span>
<input
type="text"
className="form-control"
onFocus={(this.type = "date")}
onBlur={(this.type = "text")}
placeholder="Enter your date here."
value={this.props.newLead.get("actions").get("nextActionDate")}
onChange={onFieldChanged.bind(this, "actions.nextActionDate")}
/>
</div>
</ElementsBasket>;
在输入标签中,我试图让一个占位符文本默认出现在输入字段中,当点击时我希望将类型更改为日期。问题似乎出在单击 Chrome 上的检查元素时。它不会显示 onFocus
和 onBlur
.
P/S: 甚至 onClick
似乎也有同样的问题
这是您要找的吗?
http://codepen.io/comakai/pen/WvzRKp?editors=001
var Foo = React.createClass({
getInitialState: function () {
return {
type: 'text'
};
},
onFocus: function () {
this.setState({
type: 'date'
});
},
onBlur: function () {
this.setState({
type: 'text'
});
},
render: function () {
return(
<input
type={ this.state.type }
onFocus={ this.onFocus }
onBlur={ this.onBlur }
placeholder="Enter your date here."
/>
)
}
});
React.render(<Foo/>, document.body);
正如我在上面评论的那样,render 方法第一次触发,之后在每次状态更改时触发(如果 shouldComponentRender returns true 如果它已实现):
我有以下代码
<ElementsBasket
name="nextActionDate"
data={this.props.newLead.get("actions").get("nextActionDate")}
>
<div className="form-group">
<span className="glyphicon glyphicon-calendar">Calendar </span>
<span className="glyphicon glyphicon-triangle-bottom"></span>
<input
type="text"
className="form-control"
onFocus={(this.type = "date")}
onBlur={(this.type = "text")}
placeholder="Enter your date here."
value={this.props.newLead.get("actions").get("nextActionDate")}
onChange={onFieldChanged.bind(this, "actions.nextActionDate")}
/>
</div>
</ElementsBasket>;
在输入标签中,我试图让一个占位符文本默认出现在输入字段中,当点击时我希望将类型更改为日期。问题似乎出在单击 Chrome 上的检查元素时。它不会显示 onFocus
和 onBlur
.
P/S: 甚至 onClick
似乎也有同样的问题
这是您要找的吗?
http://codepen.io/comakai/pen/WvzRKp?editors=001
var Foo = React.createClass({
getInitialState: function () {
return {
type: 'text'
};
},
onFocus: function () {
this.setState({
type: 'date'
});
},
onBlur: function () {
this.setState({
type: 'text'
});
},
render: function () {
return(
<input
type={ this.state.type }
onFocus={ this.onFocus }
onBlur={ this.onBlur }
placeholder="Enter your date here."
/>
)
}
});
React.render(<Foo/>, document.body);
正如我在上面评论的那样,render 方法第一次触发,之后在每次状态更改时触发(如果 shouldComponentRender returns true 如果它已实现):