【发布时间】:2017-11-08 11:04:02
【问题描述】:
我想将标签 <th id='1' onClick={this.click.bind(this)}> 的 id 传递给点击功能。假设我想在click() 函数console.log 中打印<th> 的ID。
这是代码-
<thead>
<tr>
<th id='name' onClick={this.click.bind(this)}>Name</th>
<th id='phone' onClick={this.click.bind(this)}>Phone number</th>
<th id='email' onClick={this.click.bind(this)}>Email</th>
</tr>
</thead>
click() 函数-
click(){
console.log('the clicked id is:') //here i want the id
}
【问题讨论】:
-
id 到底是什么意思?名称应在单击名称标签时打印?
-
onClick={this.click.bind(this, 'phone')}然后onclick(id){console.log(id)}
标签: reactjs