2
    <select id="ChangeViewId" onChange="changeView(this)"></select>

   function setView() {
 ..................... 
   var innerCode = '';
    for(i=0; i<viewList.length; i++) {                      
      innerCode += "<option value="+viewList[i]+">"+viewList[i]+"</option>";
     }
        document.getElementById("ChangeViewId").innerHTML=innerCode;
    }

function changeView(view)
    {       
        alert(document.getElementById('ChangeViewId').value);
    }

值为 C、Cpp、Java 程序。当我选择 Java 程序时,只有 Java 显示我想要完整的值 Java 程序。我已经尝试过 onSelect 和 onClick 请帮助我。

4

2 回答 2

3

The script generates this HTML:

<option value=Java program>Java program</option>

That is, an option tag that has value "Java" and a property "program". You need to add quotes around the value:

innerCode += '<option value="'+viewList[i]+'">'+viewList[i]+"</option>";
于 2013-03-06T09:01:55.857 回答
-1

这应该这样做

function setView() 
{
   var innerCode = '';
   for(i=0; i< viewList.length; i++) 
   {                      
      innerCode += '<option value="'+viewList[i]+'">' + viewList[i] + '</option>';
   }

   document.getElementById("ChangeViewId").innerHTML=innerCode;
}

function changeView(view)
{       
    var objSel = document.getElementById('ChangeViewId');
    alert(objSel.options[objSel.selectedIndex].value);
}
于 2013-03-06T09:00:28.600 回答