<分区>
编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将有助于其他人回答问题。
关闭 6 年前。
标签 javascript jquery html css
<分区>
编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将有助于其他人回答问题。
关闭 6 年前。
我正在开发一个 ReactJs 应用程序,我已经制作了一个带有表单的模式。我的问题是这样的:
在这里,所有图像都连接到单独的单选按钮,当用户单击单选按钮时,它会进行相关选择。 但是我希望即使用户单击图像而不是直接单击单选按钮时也能触发单选按钮,我该怎么做?
我的 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/