如何使用另一个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,我有一个文本节点,我无法遍历以设置所选值。
答案 0 :(得分: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。