javascript - 使复选框磁贴可点击

标签 javascript jquery html css

<分区>


关闭 6 年前

我正在开发一个 ReactJs 应用程序,我已经制作了一个带有表单的模式。我的问题是这样的:

Form with images and radio buttons

在这里,所有图像都连接到单独的单选按钮,当用户单击单选按钮时,它会进行相关选择。 但是我希望即使用户单击图像而不是直接单击单选按钮时也能触发单选按钮,我该怎么做?

我的 html:

  
<div>
  <div className="category-card">
    <label htmlFor="square">
      <div className="card-icon">
        <img src="/img/icons/recommendation/square.svg"/>
      </div>
    </label>
    <div className="card-input">
      <input type="radio" name="categories" value="square" checked={this.state.filters.categories == "square"} onChange={this.handleFilterChange.bind(this)}  id="square"/>
    </div>
  </div>

最佳答案

您可以将 for 属性与每个 label 标签一起使用。因此,换句话说, 某个输入字段 正方形 的标签。

希望对您有所帮助。

  

<div>
    
    <label for="square">
      <img src="/img/icons/recommendation/square.svg"/>
    </label>
    <input type="radio" name="categories" value="square" id="square"/>
    
    <label for="square2">
      <img src="/img/icons/recommendation/square.svg"/>
    </label>
    <input type="radio" name="categories" value="square2" id="square2"/>
    
</div>

关于javascript - 使复选框磁贴可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42122707/

上一篇:html - 使用带有 :hover 的多层菜单时奇怪的灰色底线

下一篇:css - 带有双倍高亮图片的照片墙

相关文章:

javascript - “?” 和 javascript 后面的数字是做什么用的?

javascript - jquery dlmenu动画不流畅

javascript - 对父节点感到困惑

html - 将绝对定位的 DIV *完全* 放在相对定位的父 DIV 中?

html - Firefox 的 CSS 问题,但在 Chrome 中有效

javascript - 键入 jQuery 删除类

javascript - responsive d3 area graph拉伸(stretch)圆交互点

javascript - 更改 PHP 中禁用按钮的外观

jquery - Bootstrap 3 : Collapse show one hide others

javascript - 将事件附加到对象/数组