jquery -Yii 获取所选无线电的值


<div class="form-group field-userform-custtype required">
<label class="control-label" for="custtype1">Custtype</label>
<input type="hidden" name="UserForm[custtype]" value="">
<div id="custtype1" class="flip">           
<label class="radio-inline"><input type="radio" name="UserForm[custtype]" value="1"> B2C</label>
<label class="radio-inline"><input type="radio" name="UserForm[custtype]" value="2"> B2B</label>
<label class="radio-inline"><input type="radio" name="UserForm[custtype]" value="3"> Both</label></div>
<div class="help-block"></div>
</div>

在这里,我想提取所选收音机的值。我尝试通过以下方式获得价值:

$('input:radio[name=UserForm[custtype]]:checked').val() 

但没有运气。

所需输出:1 或 2 或 3 基于选择。

请帮帮我,提前谢谢。

你的代码看起来不错。你只是忘记了名字周围的引号。它应该是这样的:

$('input:radio[name="UserForm[custtype]"]:checked').val()

希望有用!