加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react点击事件传参

发布时间:2020-12-15 07:25:51 所属栏目:百科 来源:网络整理
导读:React里的事件参数传递和传统的JS参数有些不一样,需要通过bind方法来绑定参数,第一个参数指向this,第二个参数开始才是事件函数接收到的参数 button onClick={this .handleClick .bind (this,props0,props1,...}/button handleClick (porps0,...,event) { /

React里的事件参数传递和传统的JS参数有些不一样,需要通过bind方法来绑定参数,第一个参数指向this,第二个参数开始才是事件函数接收到的参数

<button onClick={this.handleClick.bind(this,props0,props1,...}></button>

handleClick(porps0,...,event) {
    // your code here
}
showDetail:function(url){
        window.open(url);
    },render:function(){
        var o = this;
        var list = this.props.date.map(function(c){
        return(
                <li onClick={o.showDetail.bind(c,c.txtUrl)}> <h1><span className="am-badge am-badge-success am-radius ">{c.txtSource}</span>{c.title}</h1> <"price am-badge am-badge-warning am-radius ">{c.numPrice}</span> </li>
            );
        });
        return(
            <div id="result"> <ul className="am-list"> {list} </ul> </div>
        );
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读