jQuery给我任何选定的单选按钮的值相同?

use*_*873 3 jquery button radio

我有以下单选按钮:

<fieldset data-role="controlgroup" data-type="horizontal">
<legend>Business Type</legend>
<input type="radio" name="businessType" value="business" id="business" checked="checked"/>
<label for="business">Business</label>
<input type="radio" name="businessType" value="personal" id="personal"/>
<label for="personal">Personal</label>
</fieldset>
Run Code Online (Sandbox Code Playgroud)

我尝试使用这个jQuery来获取所选单选按钮的当前值,但即使我选择个人,我也会继续将'Business'作为值:

var idd = ($("input:radio[name=businessType]").val());
Run Code Online (Sandbox Code Playgroud)

谢谢

Saj*_*jid 12

根据文档,你需要做:

var idd = ($("input:radio[name=businessType]:checked").val());
Run Code Online (Sandbox Code Playgroud)