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 に答える