簡體   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