0
<div id="rads" class="formStyle selectOrder">
        <p>
             <input type="radio"  name="question" value="oui" checked >选项1
        </p>
        <p>
            <input type="radio"  name="question" value="non" > 选项2
        </p>
        <p>
            <input type="radio"  name="question" value="non" > 选项3
        </p>
    </div>
    <button class="blueBtn" onclick = "init()">替换</button>
var radioData = [{name:'紧急', value:1}, {name:'重要', value:2}, {name:'普通', value:3}];
function init(){
    for(var  i=0;i<radioData.length;i++){
            var pArray = $("#rads p");
            var radioObj = radioData[i];
            pArray[i].value =radioObj.name+"";
            
    }
    
  }

将选项1 选项2 选项3 替换成 数据中的radioData 内容 求大神指导 我的代码不起作用

查看全部 7 个回答

0
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="js/jquery-1.11.3.min.js"></script>
    <script>
        var radioData = [{
            name: '紧急',
            value: 1
        }, {
            name: '重要',
            value: 2
        }, {
            name: '普通',
            value: 3
        }];

        function init() {
            var pArray = $("p input");
            for (var i = 0; i < radioData.length; i++) {
                var radioObj = radioData[i];
                $(pArray[i]).next().text(radioObj.name);
            }
        }
    </script>
</head>

<body>
    <div id="rads" class="formStyle selectOrder">
        <p>
            <input type="radio" name="question" value="oui" checked><label>选项1<label></input>
        </p>
        <p>
            <input type="radio" name="question" value="non"><label>选项2<label>
        </p>
        <p>
            <input type="radio" name="question" value="non"><label>选项3<label>
        </p>
    </div>
    <button class="blueBtn" onclick="init()">替换</button>
</body>

</html>