To get the value of the selected radioName
item of a form with id myForm
:
(要获取ID为myForm
的表单的选定 radioName
项目的值:)
$('input[name=radioName]:checked', '#myForm').val()
Here's an example:
(这是一个例子:)
$('#myForm input').on('change', function() { alert($('input[name=radioName]:checked', '#myForm').val()); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form id="myForm"> <input type="radio" name="radioName" value="1" /> 1 <br /> <input type="radio" name="radioName" value="2" /> 2 <br /> <input type="radio" name="radioName" value="3" /> 3 <br /> </form>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…