我有一个可点击的表格行和该行中的复选框。当用户点击该行时,用户将被重定向到其他页面。这是预期的行为。现在问题出在用户点击复选框时,用户也会被重定向到其他页面。这不是预期的行为。点击复选框不应触发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();'但没有工作。 – sg552