当我运行它时,我得到“oldSelected2”未定义。这似乎适用于IE,但不适用于Chrome。问题似乎与oldSelected.children[findSelected(selectReplace)]
有关。我将下拉菜单保留在selectReplace = 0
,因此0进入oldSelected.children[]
,但是当它运行时,它返回undefined。对于放入其中的任何数字,它返回undefined。但是,在IE中,它不是undefined,而是返回对象,一切正常。我的findSelected函数底部有什么东西可以导致它破坏吗?
var selectReplace = document.getElementById(colName + index)
oldSelected = selectReplace.children[1];
oldSelected2 = oldSelected.children[findSelected(selectReplace)]
oldSelected2.removeAttribute("selected");
el = oldSelected.children[baseSiteIx.selectedIndex + 1];
el.setAttribute("selected", 1);
selectReplace.selectedIndex = findSelected(baseSiteIx) + 1;
继承人xsl
<script type="text/javascript">
var siteArray = new Array();
siteArray[0] = new Option("007", "3135", "font-family:Verdana;font-size:12px;","selected");siteArray[1] = new Option("081730", "3287", "font-family:Verdana;font-size:12px;");siteArray[2] = new Option("11", "3226", "font-family:Verdana;font-size:12px;");siteArray[3] = new Option("12", "3327", "font-family:Verdana;font-size:12px;");siteArray[4] = new Option("13", "73", "font-family:Verdana;font-size:12px;");siteArray[5] = new Option("13&", "3194", "font-family:Verdana;font-size:12px;");siteArray[6] = new Option("14", "1113", "font-family:Verdana;font-size:12px;");siteArray[7] = new Option("140", "3347", "font-family:Verdana;font-size:12px;");siteArray[8] = new Option("15", "3387", "font-family:Verdana;font-size:12px;");siteArray[9] = new Option("16", "3407", "font-family:Verdana;font-size:12px;");siteArray[10] = new Option("2001", "3487", "font-family:Verdana;font-size:12px;");siteArray[11] = new Option("2002", "3488", "font-family:Verdana;font-size:12px;");siteArray[12] = new Option("32", "3225", "font-family:Verdana;font-size:12px;");siteArray[13] = new Option("400", "3224", "font-family:Verdana;font-size:12px;");siteArray[14] = new Option("402", "3221", "font-family:Verdana;font-size:12px;");siteArray[15] = new Option("403", "3280", "font-family:Verdana;font-size:12px;");siteArray[16] = new Option("41", "3328", "font-family:Verdana;font-size:12px;");siteArray[17] = new Option("604", "3527", "font-family:Verdana;font-size:12px;");siteArray[18] = new Option("605", "3202", "font-family:Verdana;font-size:12px;");siteArray[19] = new Option("680", "3201", "font-family:Verdana;font-size:12px;");siteArray[20] = new Option("69", "3200", "font-family:Verdana;font-size:12px;");siteArray[21] = new Option("786104", "3253", "font-family:Verdana;font-size:12px;");siteArray[22] = new Option("87", "3254", "font-family:Verdana;font-size:12px;");siteArray[23] = new Option("A1A", "1153", "font-family:Verdana;font-size:12px;");siteArray[24] = new Option("ARG", "3103", "font-family:Verdana;font-size:12px;");siteArray[25] = new Option("AVK", "3281", "font-family:Verdana;font-size:12px;");siteArray[26] = new Option("AVNET", "3307", "font-family:Verdana;font-size:12px;");siteArray[27] = new Option("B1", "2533", "font-family:Verdana;font-size:12px;");siteArray[28] = new Option("BBY", "3447", "font-family:Verdana;font-size:12px;");siteArray[29] = new Option("D1", "2813", "font-family:Verdana;font-size:12px;");siteArray[30] = new Option("DAL", "3472", "font-family:Verdana;font-size:12px;");siteArray[31] = new Option("ECONTROLS", "3247", "font-family:Verdana;font-size:12px;");siteArray[32] = new Option("ECT", "3248", "font-family:Verdana;font-size:12px;");siteArray[33] = new Option("FL01", "3250", "font-family:Verdana;font-size:12px;");siteArray[34] = new Option("FL04", "3249", "font-family:Verdana;font-size:12px;");siteArray[35] = new Option("FWB", "3203", "font-family:Verdana;font-size:12px;");siteArray[36] = new Option("LEX", "3471", "font-family:Verdana;font-size:12px;");siteArray[37] = new Option("MAIN", "3134", "font-family:Verdana;font-size:12px;");siteArray[38] = new Option("MANKATO", "3219", "font-family:Verdana;font-size:12px;");siteArray[39] = new Option("MIL", "3474", "font-family:Verdana;font-size:12px;");siteArray[40] = new Option("MIS", "3468", "font-family:Verdana;font-size:12px;");siteArray[41] = new Option("PITT", "3256", "font-family:Verdana;font-size:12px;");siteArray[42] = new Option("RECEIPT", "3229", "font-family:Verdana;font-size:12px;");siteArray[43] = new Option("ST5678", "3260", "font-family:Verdana;font-size:12px;");siteArray[44] = new Option("STP", "3473", "font-family:Verdana;font-size:12px;");siteArray[45] = new Option("STPETER", "3218", "font-family:Verdana;font-size:12px;");siteArray[46] = new Option("TENN", "3257", "font-family:Verdana;font-size:12px;");siteArray[47] = new Option("TOR", "3470", "font-family:Verdana;font-size:12px;");siteArray[48] = new Option("VAN", "3467", "font-family:Verdana;font-size:12px;");siteArray[49] = new Option("VMI", "3252", "font-family:Verdana;font-size:12px;");siteArray[50] = new Option("WNJ", "3282", "font-family:Verdana;font-size:12px;");writeSelectBox(siteArray, "SiteIxFill", 1, "", "z-index:100; width: 110;");</script>
<select size="1" id="SiteIxFill" name="SiteIxFill" onchange="" style="z-index:100; width: 110;">
<option value="3468" style="font-family:Verdana;font-size:12px;">MIS</option>
<option value="3256" style="font-family:Verdana;font-size:12px;">PITT</option>
<option value="3229" style="font-family:Verdana;font-size:12px;">RECEIPT</option>
<option value="3260" style="font-family:Verdana;font-size:12px;">ST5678</option>
<option value="3473" style="font-family:Verdana;font-size:12px;">STP</option>
<option value="3218" style="font-family:Verdana;font-size:12px;">STPETER</option>
<option value="3257" style="font-family:Verdana;font-size:12px;">TENN</option>
<option value="3470" style="font-family:Verdana;font-size:12px;">TOR</option>
<option value="3467" style="font-family:Verdana;font-size:12px;">VAN</option>
<option value="3252" style="font-family:Verdana;font-size:12px;">VMI</option>
<option value="3282" style="font-family:Verdana;font-size:12px;">WNJ</option>
</select>
<input id="SiteIxFillStart" name="SiteIxFillStart" value="1" size="2">
<input id="SiteIxFillEnd" name="SiteIxFillEnd" value="1" size="2">
<input type="button" value=" Fill " size="5" onclick="fillSelectBoxes('SiteIx');">
这是找到的选择
function findSelected(el) {
var selected = null;
ec = el.children[1].children; //the table is the first child
var ecl = ec.length;
for (var i=0; i<ecl; i++) {
if (ec[i].getAttribute("selected") != null) {
if (selected == null) { // Found first selected
selected = i;
}
else
ec[i].removeAttribute("selected"); //Like I said. Only one selected!
}
}
if (selected == null)
selected = 0; //When starting this is the most logic start value if none is present
return selected;
}