[英]Dynamically creating options for selectbox using javascript
I am dynamically setting the values for a select box using java script 我正在使用Java脚本动态设置选择框的值
var dropDwnObj = document.getElementById("workingBranchCodeId");
dropDwnObj.options.length = 0;
var anOption = document.createElement("OPTION");
dropDwnObj.options.add(anOption) ;
for(var i = 0; i < jsonResult.subLocationList.length; i++) {
var anOption = document.createElement("OPTION");
dropDwnObj.options.add(anOption) ;
if(selValue == jsonResult.subLocationList[i].displayKey) {
anOption.innerHTML = jsonResult.subLocationList[i].displayValue;
anOption.value = jsonResult.subLocationList[i].displayKey;
}
}
How can I make this value as the selected value for the select box? 如何将该值作为选择框的选定值? currently it is coming like an option but i want this option to be the selected one for the select box 目前它像一个选项,但我希望此选项被选择框的选择
dropDwnObj.options [“您的选项”] .selected = true;
anOption.selected = true; anOption.selected = true;
worked for me 为我工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.