如何使用jQuery在多个单选按钮中选择最新选中的单选按钮

How to select latest checked radio button in multiple radio buttons with jQuery

本文关键字:单选按钮 选择 最新 何使用 jQuery      更新时间:2023-09-26

在此发件人中,如何使用jquery选择最新的单选按钮由用户选择

<form id = "myform">
<h3>Time to work?</h3>
  <p>
    <input type="radio" name="work" value="Hourly" />
    <input type="radio" name="work" value="Daily" />
    <input type="radio" name="work" value="Weekly" />
  </p>
<h3>Your Age?</h3>   
  <p>
    <input type="radio" name="age" value="old" />
    <input type="radio" name="age" value="young" />
    <input type="radio" name="age" value="child" />
  </p>
</form>

我试过了

$('input:checked', '#myform').val(); 

$('input[type='radio']:checked', '#myform').val();

但它总是选择第一个问题的唯一值! 有什么帮助吗?

试试这个: