jquery 获取radio被选中的值

时间:2023-03-08 17:42:53
<html>

<head>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
</head> <body> <div id="wrap">
<input type="radio" name="payMethod" value="1" />支付宝
<input type="radio" name="payMethod" checked value="2" />微信
</div> <script> /** 获取被选中按钮的值 **/
var val_payPlatform = $('#wrap input[name="payMethod"]:checked ').val(); console.log(val_payPlatform);
alert(val_payPlatform); </script> </body>
</html>