Closed Seasons123 closed 6 years ago
一、简单来说: var val = $('input[name="sex"]:checked').val();
var val = $('input[name="sex"]:checked').val();
二、整体代码:
<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="utf-8"> <title>获取单选按钮选中的值</title> </head> <body> <label><input type="radio" name="sex" value="m" checked="checked">男</label> <label><input type="radio" name="sex" value="f">女</label> <button>提交</button> <script type="text/javascript" src="jquery-1.11.3.min.js"></script> <script type="text/javascript"> $(function(){ $('button').click(function(){ var val = $('input[name="sex"]:checked').val(); console.log(val); }); }) </script> </html>
一、简单来说:
var val = $('input[name="sex"]:checked').val();
二、整体代码: