繁体   English   中英

所有单选按钮都被选中?

[英]All radio buttons are selected?

我的 jQuery 代码和我的单选按钮有问题,如果我选择了一个按钮而另一个他保持选中状态,我不知道如何解决这个问题,如果有人可以帮助我解决我的问题,谢谢。 我留下我的代码和屏幕截图,看看实际发生了什么。

在此处输入图像描述

 $("#custom").click(function() { $(".custom").css({ "display": "block" }) }) $("#man").click(function() { $(".custom").css({ "display": "none" }) }) $("#ladies").click(function() { $(".custom").css({ "display": "none" }) });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input type="radio" id="ladies" name="ladies" value="ladies"> <label for="ladies">Ladies</label> <input type="radio" id="man" name="man" value="man"> <label for="man">Man</label> <input type="radio" id="custom" name="custom" value="custom"> <label for="custom">Custom</label> <a href="#" class="icons"><i class="fas fa-question-circle fa-1x"></i></a> <div class="custom"> <form action="#"> <select name='gender' id='gender'> <option value='gender' disabled>Select the pronoun you are using</option> <option value='she'>She: "Wihs her a happy brithday"</option> <option value='he'>He: "Wish him a happy birthday:"</option> <option value='he/she'>He / She. "Wish him / her a happy birthday!"</option> </select> <p class="genderTxt">The chosen pronoun is visible to everyone.</p> <input type="text" class="optionalG" placeholder="Gender (optional)"> </form> </div>

我没有任何错误信息要显示。

所有<input type="radio">标签都需要相同的name属性。 然后它将起作用。

 <input type="radio" id="ladies" name="gender" value="ladies" checked> <label for="ladies">Ladies</label> <input type="radio" id="man" name="gender" value="man"> <label for="man">Man</label> <input type="radio" id="custom" name="gender" value="custom"> <label for="custom">Custom</label>

单选按钮组上的名称属性需要具有相同的名称。

改变这个:

 <input type="radio" id="ladies" name="ladies" value="ladies">
 <label for="ladies">Ladies</label>

 <input type="radio" id="man" name="man" value="man">
 <label for="man">Man</label>

 <input type="radio" id="custom" name="custom" value="custom">
 <label for="custom">Custom</label>

对此

 <input type="radio" id="ladies" name="radioGroup" value="ladies">
 <label for="ladies">Ladies</label>

 <input type="radio" id="man" name="radioGroup" value="man">
 <label for="man">Man</label>

 <input type="radio" id="custom" name="radioGroup" value="custom">
 <label for="custom">Custom</label>

名称不必是“radioGroup”,但必须相同,这样代码才能分辨出哪些单选按钮组属于一起。

暂无
暂无

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

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