【发布时间】:2017-11-25 15:14:16
【问题描述】:
我在该行中有一个可点击的表格行和复选框。当用户单击该行时,用户将被重定向到其他页面。这是预期的行为。现在的问题是当用户单击复选框时,用户也将被重定向到其他页面。这不是预期的行为。点击复选框不应该触发redirect()方法
handleChange(e) {
this.setState({
checkbox: e.target.checked,
});
}
redirect() {
Router.push('/registration/register/RegisterEditor', '/verification/e7fe5b68-94e8-435f-8303-5308fd1f7e69');
}
<tbody>
{inventory.list().map((data, index) => (
<tr key={'asset'.concat(index)} onClick={() => { this.redirect(); }} tabIndex={index + 1} role="button">
<td className="text-center">{index + 1}</td>
<td>{data.item}</td>
<td width="3%">
<Input className="mx-auto" type="checkbox" onChange={this.handleChange} />
</td>
</tr>
))}
</tbody>
输出:
我该如何解决这个问题?提前致谢。
【问题讨论】:
-
您是否在复选框点击处理程序中尝试过
stopPropagation? -
是的,我在
handleChange()方法中添加了e.stopPropagation();但没有用。
标签: javascript reactjs checkbox