[英]Dynamic Drop down not working in IE11?
var vehicleLineDD = document.getElementById("vehicleLineDD");
for (i = 0; i < arr.length; i++) {
vehicleLineOp.text = arr[i].code + ': ' + arr[i].desc;
vehicleLineOp.value = arr[i].code;
vehicleLineDD.add(vehicleLineOp, null);
}
Hi Friends, here I am attach my code where I have struck now. 嗨,朋友们,我在这里附上我现在击中的代码。 Problem is vehicleLineDD is the dynamic drop down.
问题是vehicleLineDD是动态下拉列表。 Depends on another drop down I should load the values here.
取决于另一个下拉菜单,我应该在此处加载值。 It is working fine in IE8, but in IE11 all the values are coming properly except vehicleLineDD.add(vehicleLineOp, null);
在IE8中工作正常,但在IE11中,除vehicleLineDD.add(vehicleLineOp,null);之外的所有值都正确显示。 is not adding the values, only last value alone added.
不添加值,仅添加最后一个值。 Every time when change the first drop down here I can see only one option.
每次更改第一个下拉菜单时,我只能看到一个选项。 Could anyone help me to come out from the the problem.
谁能帮助我解决问题。 Thanks in advance.
提前致谢。
You need to create a new option element for the vehicleLineOp variable(using code similar to vehicleLineOp = document.createElement("option");
), otherwise you're just constantly updating the same option element with different text and value attributes (which is why only the last applied text and value are showing up). 您需要为vehicleLineOp变量创建一个新的option元素(使用类似于
vehicleLineOp = document.createElement("option");
),否则,您将不断更新具有不同文本和值属性(即为什么只显示最后应用的文本和值)。
var vehicleLineOp;
var vehicleLineDD = document.getElementById("vehicleLineDD");
for (i = 0; i < arr.length; i++) {
vehicleLineOp = document.createElement("option");
vehicleLineOp.text = arr[i].code + ': ' + arr[i].desc;
vehicleLineOp.value = arr[i].code;
vehicleLineDD.add(vehicleLineOp);
}
Edit: Here's a working example that should work in both IE11 and IE8: 编辑:这是一个应在IE11和IE8中都可以使用的工作示例:
function populate() { var arr = document.getElementById("input").value.split("\\n"); var vehicleLineOp; var vehicleLineDD = document.getElementById("vehicleLineDD"); vehicleLineDD.innerHTML = ""; for (var i = 0; i < arr.length; i++) { vehicleLineOp = document.createElement("option"); vehicleLineOp.text = arr[i]; vehicleLineOp.value = arr[i]; vehicleLineDD.add(vehicleLineOp); } } var btn = document.getElementById("btnPopulate"); if (btn.addEventListener) { btn.addEventListener("click", populate); } else { btn.attachEvent("onclick", populate); }
Add each choice as a new line in the text area below, thn click "Populate Dropdown":<br/> <textarea id="input" style="vertical-align:top;height:4em;">Example 1 Example 2 Example 3</textarea> <input type="button" value="Populate Dropdown" id="btnPopulate" /> <br/> <select id="vehicleLineDD"></select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.