js获取和设置radio的值


<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>获取radio的值title>
    <script type="text/javascript">
        function test(){
            var radios = document.getElementsByName("loan");
            var value = 0;
            for(var i=0;iif(radios[i].checked == true){
                    value = radios[i].value;
                }
            }
            alert(value);
        }
    script>
head>
<body>
    <input type="radio" name="loan" value="1" checked="checked" onclick="test()"><input type="radio" name="loan" value="2" onclick="test()"><input type="radio" name="loan" value="3" onclick="test()">保密
    <input type="button" name="get" value="获取" >
body>
html>
  • 设置
$("#id").prop("checked",true);

你可能感兴趣的:(js笔记)