0

我有一个与选择/选项一起使用的 html 页面,我想将此功能转换为 input type=radio(列表到单选按钮)。

实际上我有一个这样的选择列表:

<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 值

如果我想将选择转换为输入类型=收音机,首先我将选择更改为:

<input name="DEC-51537a4b580452b9e145b75c-A" type="radio" checked value="A">A
<input name="DEC-51537a4b580452b9e145b75c-A" type="radio" value="R">R

这里的javascript函数适用于选择但不适用于单选按钮:

  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');

但这还不够。我错过了什么?

4

0 回答 0