我有一个 label
用“for="the pointer to the checkbox input"
”据我所知,这个for
只能为 label
添加.因此,我需要在 label
里面添加一个<button>
(我需要它),但点击事件无法正常工作 - 它没有选中 for
的复选框指向。
如果我必须放置<button>
,我可以在这里使用什么可能性?在label
里面, 只用 html+css 编码?
一些代码例如:
<input type="checkbox" id="thecheckbox" name="thecheckbox">
<div for="thecheckbox"><button type="button">Click Me</button></div>
最佳答案
事实证明你可以做一个 <button>
操作一个输入,但前提是你把 <label>
在 <button>
.
<button type="button">
<label for="my-checkbox">Button go outside the label</label>
</button>
<input type="checkbox" id="my-checkbox">
尽管这违反了 W3C 规范:
The interactive element label must not appear as a descendant of the button element. https://www.w3.org/TR/html-markup/label.html
关于html - 标签内的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37504383/