0

你如何用另一个 ddl 填充一个 ddl 并与 Internet Explorer 兼容,同时仍然能够横穿选项数组来设置选定的选项?

/*******************************************************************************
*  Function: func_copy_all
*  Created By: A. Fulton
*  Created Date: 3/8/2013
*  For Release or Issue: RSP5.02
*  Modified Date: 
*  Purpose:  Populate city ddls and selecteds.
*******************************************************************************/
function func_copy_all()
{

  var ln_start_location = ((Number(document.getElementById('page_index').value) - 1) * Number(document.getElementById('page_size').value)) +1;
  for(i = ln_start_location; i < (ln_total_rows + 1); i++){
    //load the current city ddl with options
    var lo_city = document.getElementById('city_'+i);
    var lo_temp_city = document.getElementById('temp_city_selection');
         /*For IE*/
         var node = document.getElementById('city_cell_' + i);
         var lo_cell = document.createElement("TD");
         var lo_textNode = document.createTextNode(lo_temp_city);
         lo_cell.appendChild(lo_textNode);
         node.appendChild(lo_cell);

    //Believe innterHTML inside a div might be a problem for IE
    //lo_city.innerHTML = lo_temp_city.innerHTML;  

    //option value that needes to be selected
    var ls_selected_city = document.getElementById('city2_'+i).value;
    //Get the length of the ddl
    var optCount = lo_temp_city.options.length;
    //Traverse the array to get the index and set it to the city to selected
    for(var ln_j = 0; ln_j < optCount; ln_j++){
      if(lo_temp_city.options[ln_j].value == ls_selected_city){
      //set selected and break
      lo_city.options[ln_j].selected = "true";
      //break
      ln_j = optCount + 1;
      }
    }
  }
}

如果我使用innerHTML,我可以让它在firefox上正常工作,但不能在IE上工作?如果我避免使用 innerHTML,我有一个文本节点,我无法遍历该节点来设置所选值。

4

1 回答 1

0
/*******************************************************************************
*  Function: func_copy_all
*  Created By: A. Fulton
*  Created Date: 3/8/2013
*  For Release or Issue: RSP5.02
*  Modified Date: 
*  Purpose:  Populate city ddls and selecteds.
*******************************************************************************/
function func_copy_all()
{
  var ln_start_location = ((Number(document.getElementById('page_index').value) - 1) * Number(document.getElementById('page_size').value)) +1;
  var lo_node;
  for(var i = ln_start_location; i < (ln_total_rows + 1); i++){
    var lo_temp_city = document.getElementById('temp_city_selection').cloneNode(true);
    /*For IE*/
    lo_node = document.getElementById('city_cell_' + i);
    lo_temp_city.setAttribute("id", 'city_' + i);
    lo_temp_city.setAttribute("jselected", 'city_' + i);
    lo_temp_city.setAttribute("name", 'city_' + i);

    //option value that needes to be selected
    var ls_selected_city = document.getElementById('city2_'+i).value;

    //Get the length of the ddl
    var optCount = lo_temp_city.options.length;

    //Traverse the array to get the index and set it to the city to selected
    for(var ln_j = 0; ln_j < optCount; ln_j++){
      if(lo_temp_city.options[ln_j].value == ls_selected_city){
      //set selected and break
      lo_temp_city.options[ln_j].selected = "true";
      //break
      ln_j = optCount + 1;
      }
    }
    //Add temp city to the city cell
    lo_node.appendChild(lo_temp_city);
  }
}

这适用于 Firefox 和 IE8。

于 2013-03-15T17:59:08.203 回答