在JavaScript中动态添加选择/选项,不适用于IE

时间:2018-07-20 18:56:08

标签: javascript dynamic

此代码在Firefox中可以正常工作,但在IE 9中却不能:       var numLocations = Lookup_EngineLocations(value,strState,strTown)

  var catOptions = "";
  var x          = 0;
  var newSel     = document.getElementById ( "LOCATIONS" );
  var opt;

  newSel.innerHTML = "<option value='0'>Select</option>";

  alert ( "Got here with " + newSel.innerHTML);

  for ( x=0; x < numLocations; x++ )
     {
     opt = document.createElement("option");
     opt.value = strLocationsID        [x];
     opt.text  = strLocationsLOCATIONS [x];

     newSel.appendChild ( opt );
     }

  alert ( "Got here with " + newSel.innerHTML);
  alert ( "Got here with " + document.getElementById ( "LOCATIONS" ).innerHTML);

尽管我显然要添加一个值和一个文本元素,但两个alert()调用都提供了正确的内容,但下拉列表包含了所有空白内容。

杰里

0 个答案:

没有答案