English 中文(简体)
Dropdown not being population in IE?
原标题:Dropdown not getting populated in IE?
  • 时间:2009-10-06 10:47:16
  •  标签:

我试图根据选定的类别清单中选择的类别,将数值列入一个子类的选定清单。 似乎还没有在IEE工作。 谁能提出问题?

在S.C.R.C.R.C.R.C.R.C.R.R.C.R.R.R.,I.在I.R.C.R.C.R.C.R.C.R.C.R.R.C.R.R.R.R.R.R.R.R.R.,I.在I.R.C.R.R.C.R.R.R.R.中,I.在I.R.C.R.C.R.R.C.R.R.R.R.R.R.C.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.

<body onload="setSubcategories(default_value);">

在小标题档案中,我有类似的东西。

 subcategories = new Array();
 subcategories[ Lifestyle ] = [ All ,
                                   Beauty (SHC) ,
                                   Skin Care ,
                                   Hair Care ,
                                   Oral Care ,
                                   Cosmetics ,
                                   Footwear ,
                                   Jewelry ,
                                   Male Styling ,
                                   Women Hygiene ,
                                   Womens magazines ,
                                   Apparels ,
                                    Fashion (AFA) ,
                                   Spa ,
                                   Accessories 
                                  ];
    subcategories[ Automobiles ] = [ All ,
                            Automobiles (C&B) ,
                            Cars ,
                            Bikes ,
                            Car Magazine ,
                            Bikes Magazine ,
                            Accessories 
                       ];
    subcategories[ FoodandBeverage ] = [ All ,
                                   Snacking ,
                                   Confectionary ,
                                   Beverages ,
                                   Generic F&B ,
                                   Restaurant Review ,
                                   Food Reviews ,
                                   Wines & Vineyards 
                              ];


function setSubcategories(default_value){
    default_value = (typeof default_value ==  undefined ) ?
              All  : default_value;
    var elem = document.getElementById( id-category );
    if(elem == null){return false;}

    var category = elem.value;
    var subelem = document.getElementById( id-subcategory );
    var html = "";
    var subcategoriesArr = subcategories[category];
    for(var i=0; i < subcategoriesArr.length; i++){
        var selected = subcategoriesArr[i] == default_value ? " selected" : "";
        html +=  <option  + selected +  >  + subcategoriesArr[i] +  </option>
 ;
    }
    subelem.innerHTML = html;
}
最佳回答

采用相当于DOM当量的工艺:

var subcategoriesArr = subcategories[category];
for(var i=0; i < subcategoriesArr.length; i++){
    var option = document.createElement( option );
    option.value = option.text = subcategories[i];
    option.selected = (subcategoriesArr[i] == default_value);
    subelem.appendChild(option);
}
问题回答

利用设定<代码>Option物体并添加到options/code>的按时间顺序排列的方法 收集:

var subcategoriesArr = subcategories[category];
var i, len, selected, optionText;

// Clear any existing options
subelem.options.length = 0;

// Create new options
for (i = 0, len = subcategoriesArr.length; i < len; i++){
  selected = (subcategoriesArr[i] === default_value);
  optionText = subcategoriesArr[i];
  subelem.options[i] = new Option(optionText, optionText, selected, selected);
}

此前,我曾碰到了这一ug。 您可在Internet Exploration上就选定要素设定inner Rainbow/code>。 您必须总结一下四舍五入(或其它部分)的选定内容,然后为包括你希望插入的备选办法在内的新选定要素打上标记。

这里的缩略语:

  1. Target the select
  2. Wrap the select in a div element
  3. Store the markup of the select for later reuse (step #5) and clear the contents of the div
  4. Generate markup for options
  5. Include that markup in the stored select markup
  6. Put the whole thing inside the div surrounding the select

不用说:我最后采用纯粹的OM办法。 这是一种耻辱,因为它比使用<条码>内超文本<>/代码>要慢得多。





相关问题