防止点击标签触发子按钮

古加·菲格雷多(Guga Figueiredo)

像这样进行设置时,单击带有子按钮的标签会触发按钮的onclick事件:

function fireButton() {
  console.log("Button fired!");
}
<label>Label
  <button onclick="fireButton()">Button</button>
</label>

有办法防止这种情况吗?

尤夫拉伊·穆勒

为标签添加属性。

function fireButton() {
  console.log("Button fired!");
}
<label for=''>Label
  <button onclick="fireButton()">Button</button>
</label>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章