简体   繁体   English

如何使4组3个按钮同时保持单击状态?

[英]How do i make 4 sets of 3 buttons stay clicked in at the same time?

I'm creating 4 sets of 3 buttons that are linked together in a row. 我正在创建4组3个按钮,它们连续链接在一起。 One set includes a button with a checkmark sign and a button with nothing and a button with an X. The purpose is to use the buttons to show if you're Okay with something or don't care or don't want something. 一组包括带有对勾标记的按钮,没有按钮的按钮和带有X的按钮。目的是使用这些按钮来显示您对某事还可以,或者不在乎或不需要。

The problem is that I have 4 sets of these buttons, but I can only press down 1 button at at time for all the 4 sets! 问题是我有4套这些按钮,但是我一次只能同时按下所有4套按钮中的1个! I need to press down one button per set, so there can be 4 buttons pressed at the same time. 我需要每组按下一个按钮,因此可以同时按下4个按钮。

I hope you understand my problem. 希望你能理解我的问题。

 <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;">&#10003</button> <input type="radio" hidden name="_groupname" value="what-gets-submitted" /> <button type="button" class="cstm-rad2" onclick="this.previousElementSibling.checked=true;">&#10005</button> <input type="radio" hidden name="_groupname" value="what-gets-submitted" /> <button type="button" class="cstm-rad3" onclick="this.previousElementSibling.checked=true;">&#10005</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;">&#10003</button> <input type="radio" hidden name="_groupname" value="what-gets-submitted" /> <button type="button" class="cstm-rad2" onclick="this.previousElementSibling.checked=true;">&#10005</button> <input type="radio" hidden name="_groupname" value="what-gets-submitted" /> <button type="button" class="cstm-rad3" onclick="this.previousElementSibling.checked=true;">&#10005</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;">&#10003</button> <input type="radio" hidden name="_groupname" value="what-gets-submitted" /> <button type="button" class="cstm-rad2" onclick="this.previousElementSibling.checked=true;">&#10005</button> <input type="radio" hidden name="_groupname" value="what-gets-submitted" /> <button type="button" class="cstm-rad3" onclick="this.previousElementSibling.checked=true;">&#10005</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;">&#10003</button> <input type="radio" hidden name="_groupname" value="what-gets-submitted" /> <button type="button" class="cstm-rad2" onclick="this.previousElementSibling.checked=true;">&#10005</button> <input type="radio" hidden name="_groupname" value="what-gets-submitted" /> <button type="button" class="cstm-rad3" onclick="this.previousElementSibling.checked=true;">&#10005</button> </div> </div> 

you can use different name for each group because that's how you group radio buttons 您可以为每个组使用不同的名称,因为这是对单选按钮进行分组的方式

I also modified the value because that's how you can know which one is selected later in your JS 我还修改了该value因为这样您就可以知道以后在JS中选择了哪个

note : removed the hidden from the radio because with my browser I can't differentiate pressed button from no-pressed ones hope your css solve this ;) 注意:从无线电中删除了隐藏的内容,因为在我的浏览器中,我无法将按下的按钮与未按下的按钮区分开,希望您的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;">&#10003</button> <input type="radio" name="_groupname1" value="noCare" /> <button type="button" class="cstm-rad2" onclick="this.previousElementSibling.checked=true;">&#10005</button> <input type="radio" name="_groupname1" value="no" /> <button type="button" class="cstm-rad3" onclick="this.previousElementSibling.checked=true;">&#10005</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;">&#10003</button> <input type="radio" name="_groupname2" value="noCare" /> <button type="button" class="cstm-rad2" onclick="this.previousElementSibling.checked=true;">&#10005</button> <input type="radio" name="_groupname2" value="no" /> <button type="button" class="cstm-rad3" onclick="this.previousElementSibling.checked=true;">&#10005</button> </div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM