我有一个与select / option一起使用的html页面,我想将此功能转换为input type = radio(list to radio butons)。
实际上我有一个这样的选择列表:
<select name="DEC-51537a4b580452b9e145b75c-A">
<option selected="" value="OK">OK</option>
<option value="NOK">NOK</option>
</select>
<select name="DEC-51537a4b58045459e145b75c-R">
<option selected="" value="OK">OK</option>
<option value="NOK">NOK</option>
</select>
<select name="DEC-51537a88880452b9e145b75c-A">
<option selected="" value="OK">OK</option>
<option value="NOK">NOK</option>
</select>
用户选择他想要的值并单击按钮。按钮调用javascript,获取每个“DEC - ”的结果。
对于以“DEC-”开头的每个选择,我检索: - dec-number(例如51537a88880452b9e145b75c) - 原始dec值(A或R) - 我得到select.value以检索用户选择的dec值
如果我想将select转换为input type = radio,首先我要更改select to this:
<input name="DEC-51537a4b580452b9e145b75c-A" type="radio" checked value="A">A
<input name="DEC-51537a4b580452b9e145b75c-A" type="radio" value="R">R
这里的javascript函数适用于select而不是单选按钮:
var elements = $doc.getElementsByTagName('select');
var sel;
for(var i=0; i<elements.length; i++){
sel = elements[i];
if(sel.name.indexOf('DEC-') === 0){
var selName = sel.name.split('-');
var oid = selName[1];
var originalDecision = selName[2];
var supervisorDecision = sel.value;
decisions++;
if(originalDecision == supervisorDecision) {
rightDecisions++;
} else {
wrongDecisions++;
if(originalDecision == "ACCEPTED") {
originalDecision="<h3 class='green'>ACCEPTED</h3>";
} else if(originalDecision == "REFUSED") {
originalDecision="<h3 class='red'>REFUSED</h3>";
}
if(supervisorDecision == "ACCEPTED") {
supervisorDecision="<h3 class='green'>ACCEPTED</h3>";
} else if(supervisorDecision == "REFUSED") {
supervisorDecision="<h3 class='red'>REFUSED</h3>";
}
var content = $doc.getElementById(oid).innerHTML;
wrongDecisionsTab += "<tr><td>" + content + "</td><td>"
+ originalDecision + "</td><td><h3>" + supervisorDecision + "</h3></td></tr>";
}
}
}
我需要相同的东西,但有单选按钮,所以我试图改变:
var elements = $doc.getElementsByTagName('input');
但这还不够。 我错过了什么?