Jquery 单选按钮组,需要选择一个

Jquery 单选按钮组,需要选择一个,jquery,jquery-validate,Jquery,Jquery Validate,我知道有人以某种形式问过这个问题,但我想看看是否有人有答案。我似乎不明白。我需要在标签旁边放一个星号,然后让用户选择其中一个选项。我们正在使用验证插件。到目前为止,我已经尝试了很多方法,但都没有效果。有什么想法吗 //Radio button group that needs one choice to validate, else show an error <div class="field" > <div class="label-cont"> &

我知道有人以某种形式问过这个问题,但我想看看是否有人有答案。我似乎不明白。我需要在标签旁边放一个星号,然后让用户选择其中一个选项。我们正在使用验证插件。到目前为止,我已经尝试了很多方法,但都没有效果。有什么想法吗

//Radio button group that needs one choice to validate, else show an error

<div class="field" >
    <div class="label-cont">
    <label for="null" class="am_radio field-label"> What is the main purpose of this email?</label>
</div>
   <ul title="What is the main purpose of this email?" class="radiolist">
    <li>
        <input name="attribute_service_copy_purpose_value" id="am_attribute_service_copy_purpose_value_0" type="radio" class="amRadio" value="Visibility"><label class="radiolabel" for="am_attribute_service_copy_purpose_value_0">Visibility</label></li>  

          <li>
             <input name="attribute_service_copy_purpose_value" id="am_attribute_service_copy_purpose_value_1" type="radio" class="amRadio" value="Drive Traffic"><label class="radiolabel" for="am_attribute_service_copy_purpose_value_1">Drive Traffic</label></li>

               <li><input name="attribute_service_copy_purpose_value" id="am_attribute_service_copy_purpose_value_2" type="radio" class="amRadio" value="Brand Enhancement"><label class="radiolabel" for="am_attribute_service_copy_purpose_value_2">Brand Enhancement</label></li>
                    </ul>
                        </div>
//需要一个选项进行验证的单选按钮组,否则显示错误
这封电子邮件的主要目的是什么?
  • 能见度
  • 驱车
  • 品牌提升

我看不到jquery在代码中的任何地方进行验证,所以假设这只是一个选项。您可以使用HTML5的本机表单验证,当它们(在一个组中)都具有相同的名称时,生成所需的单选按钮之一

以下是一个例子:

<form action="http://some.randompageonthe.net">  
  <p>  
    <label><input type="radio" name="r" value="a" required> A</label><br>
    <label><input type="radio" name="r" value="b" required> B</label><br>
    <label><input type="radio" name="r" value="c" required> C</label><br>   
  </p>
  <input type="submit">
</form>


A
B
C


几天前,我面临着同样的情况。 一个简单的解决方案是,您可以将其中一个单选按钮默认设置为“选中”

 <label><input type="radio" name="r" value="a" checked> A</label><br>
 <label><input type="radio" name="r" value="b" > B</label><br>
 <label><input type="radio" name="r" value="c" > C</label><br>
A
B
C

在此之后,您将不需要对其进行验证。

谢谢,这实际上是一个呈现HTML的PHP表单,因此很遗憾,我不能使用这种方式。