【问题标题】:Image selection input in html with checkbox or radio带有复选框或单选框的 html 中的图像选择输入
【发布时间】:2022-07-02 02:47:23
【问题描述】:

我正在创建一个网页,我想创建一个带有图像的部分,以便用户通过单击它只能选择一个。我正在尝试使用复选框和收音机,但只有在我按下复选框本身时才会被选中,而不是在图像中。我该怎么做?

我试过了:

<section>
        <fieldset>
                <legend><h2>Favorite character</h2></legend>
    
                <input type="checkbox" id="imagen">
                <label for="imagen"><img src="image.jpg"></label>
        </fieldset>
</section>

也一样,但有收音机

【问题讨论】:

  • 标签标签中的for 属性应与输入的id 匹配

标签: html image checkbox radio-button


【解决方案1】:

<section>
        <fieldset>
                <legend><h2>Favorite character</h2></legend>
    
                <input type="checkbox" id="imagen">
                <label for="imagen"><img src="image.jpg"></label>
        </fieldset>
</section>

您必须为 for of 标签指定与输入的 id 相同的名称。 将此应用到您的代码中,它将起作用。

【讨论】:

  • ups...好吧,但我改变了它,我仍然无法通过图像选择输入,仍然只是通过输入本身
最近更新 更多