猿问

JS中如何替换掉<p>标签中的内容 请大神指教

<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 内容 求大神指导 我的代码不起作用

侃侃无极
浏览 3966回答 1
1回答

心有法竹

var oBox = document.getElementsByTagName("p");&nbsp; &nbsp; var radioData = [{name:'紧急', value:1}, {name:'重要', value:2}, {name:'普通', value:3}];&nbsp; &nbsp; &nbsp; for(var i=0;i<radioData.length;i++){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log(oBox)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oBox[i].childNodes[2].nodeValue=radioData[i].name&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp;&nbsp;
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答