php - 如何让 4 组 3 个按钮同时保持点击状态?
问题描述
我正在创建 4 组 3 个按钮,它们连续链接在一起。一组包括一个带有复选标记符号的按钮和一个没有任何内容的按钮和一个带有 X 的按钮。目的是使用这些按钮来显示您是否可以接受某事或不关心或不想要某事。
问题是我有 4 组这些按钮,但是我一次只能按下 1 个按钮来全部 4 组!我需要每组按下一个按钮,因此可以同时按下 4 个按钮。
我希望你能理解我的问题。
<div id="midt">
<div id="box1">
<h1>Musik</h1>
<input type="radio" hidden name="_groupname" value="what-gets-submitted" />
<button type="button" class="cstm-rad1" onclick="this.previousElementSibling.checked=true;">✓</button>
<input type="radio" hidden name="_groupname" value="what-gets-submitted" />
<button type="button" class="cstm-rad2" onclick="this.previousElementSibling.checked=true;">✕</button>
<input type="radio" hidden name="_groupname" value="what-gets-submitted" />
<button type="button" class="cstm-rad3" onclick="this.previousElementSibling.checked=true;">✕</button>
</div>
<div id="box2">
<h1>Børn</h1>
<input type="radio" hidden name="_groupname" value="what-gets-submitted" />
<button type="button" class="cstm-rad1" onclick="this.previousElementSibling.checked=true;">✓</button>
<input type="radio" hidden name="_groupname" value="what-gets-submitted" />
<button type="button" class="cstm-rad2" onclick="this.previousElementSibling.checked=true;">✕</button>
<input type="radio" hidden name="_groupname" value="what-gets-submitted" />
<button type="button" class="cstm-rad3" onclick="this.previousElementSibling.checked=true;">✕</button>
</div>
</div>
<div id="midt2">
<div id="box3">
<h1>Dyr</h1>
<input type="radio" hidden name="_groupname" value="what-gets-submitted" />
<button type="button" class="cstm-rad1" onclick="this.previousElementSibling.checked=true;">✓</button>
<input type="radio" hidden name="_groupname" value="what-gets-submitted" />
<button type="button" class="cstm-rad2" onclick="this.previousElementSibling.checked=true;">✕</button>
<input type="radio" hidden name="_groupname" value="what-gets-submitted" />
<button type="button" class="cstm-rad3" onclick="this.previousElementSibling.checked=true;">✕</button>
</div>
<div id="box4">
<h1>Rygning</h1>
<input type="radio" hidden name="_groupname" value="what-gets-submitted" />
<button type="button" class="cstm-rad1" onclick="this.previousElementSibling.checked=true;">✓</button>
<input type="radio" hidden name="_groupname" value="what-gets-submitted" />
<button type="button" class="cstm-rad2" onclick="this.previousElementSibling.checked=true;">✕</button>
<input type="radio" hidden name="_groupname" value="what-gets-submitted" />
<button type="button" class="cstm-rad3" onclick="this.previousElementSibling.checked=true;">✕</button>
</div>
</div>
解决方案
您可以为每个组使用不同的名称,因为这就是您对单选按钮进行分组的方式
我还修改了,value
因为这样你就可以知道稍后在你的 JS 中选择了哪一个
注意:从收音机中删除了隐藏,因为使用我的浏览器我无法区分按下按钮和未按下按钮希望你的 css 解决这个问题;)
<div id="midt">
<div id="box1">
<h1>Musik</h1>
<input type="radio" name="_groupname1" value="yes" />
<button type="button" class="cstm-rad1" onclick="this.previousElementSibling.checked=true;">✓</button>
<input type="radio" name="_groupname1" value="noCare" />
<button type="button" class="cstm-rad2" onclick="this.previousElementSibling.checked=true;">✕</button>
<input type="radio" name="_groupname1" value="no" />
<button type="button" class="cstm-rad3" onclick="this.previousElementSibling.checked=true;">✕</button>
</div>
<div id="box2">
<h1>Børn</h1>
<input type="radio" name="_groupname2" value="yes" />
<button type="button" class="cstm-rad1" onclick="this.previousElementSibling.checked=true;">✓</button>
<input type="radio" name="_groupname2" value="noCare" />
<button type="button" class="cstm-rad2" onclick="this.previousElementSibling.checked=true;">✕</button>
<input type="radio" name="_groupname2" value="no" />
<button type="button" class="cstm-rad3" onclick="this.previousElementSibling.checked=true;">✕</button>
</div>
</div>
推荐阅读
- wso2 - 使用 SAML2 访问 travelocity.com / saml2-web-app-pickup-dispatch.com 应用程序时签名验证失败
- php - 根据日期对多维数组进行排序
- python - GeoDjango migrate 给出以下错误 - ValueError: Cannot use object with type int for a spatial lookup parameter
- regex - 在 ruby 正则表达式中,我可以匹配除字符串之外的任何字符吗?
- raspberry-pi - 无板树莓派硬件模拟
- architecture - 在 CQRS 模式中的命令处理程序中查询数据库
- java - 在for循环中找到最大值
- swift - NStimer 和 Dispatchqueue 在使用 airpot 时启动有点晚
- javascript - 在 handleChange Typescript 中传递值
- ios - flutter iOS有白屏