onFocus和onBlur没有做出反应

gat*_*tes 26 javascript-events reactjs

我有以下代码

<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>
Run Code Online (Sandbox Code Playgroud)

在输入标记中,我正在尝试默认情况下在输入字段中显示占位符文本,并且在单击时我希望将类型更改为日期.问题似乎是当点击chrome上的inspect元素时.它不会显示onFocus和onBlur.

Ps:即使是onClick似乎也有同样的问题

com*_*oma 31

这是你想要的?

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);
Run Code Online (Sandbox Code Playgroud)

正如我上面所评论的那样,render方法首次触发,然后在每次状态更改时触发(如果shouldComponentRender在实现的情况下返回true):

https://facebook.github.io/react/docs/component-specs.html