<p 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>
</p>
<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+"";
}
}
Replace option 1, option 2, and option 3 with the radioData content in the data. Please guide me. My code does not work.
var oBox = document.getElementsByTagName("p");
What you want to replace is the value of input, not the value of p, and get each input
There is no big problem with your code, no major changes are needed
pArray[i].innerHTML =radioObj.name+""; Just change the value to innerHTML
Hello, in your question, you want to replace
<input>
标签后面的文本,而不是标签的value
值。所以,你使用
pArray[i].value =radioObj.name+"";
which is incorrect.The following is the code I gave for reference only: