当我尝试从javascript中的Listbox项获取文本时,它总是返回undefined。
winkeloptie.value = winkels[i][0];
winkeloptie.text = (winkels[i][0]);
alert(winkeloptie.value) ///This returns the value very nicely
alert(winkeloptie.text) //Returns undefined
我如何获取文字?
编辑:了解更多信息:
function addWinkels(){
var winkellijst = document.getElementById('winkel');
for (var i = 0;i < winkels.length;i++){
var winkeloptie = document.createElement("Option");
winkeloptie.text = (winkels[i][0]);
winkeloptie.title = (winkels[i][1]);
winkeloptie.value = winkels[i][0];
winkellijst.options.add(winkeloptie);
}
}
答案 0 :(得分:0)
答案 1 :(得分:0)
var x=document.getElementById("mySelect").selectedIndex;
var y=document.getElementById("mySelect").options;
alert("Index: " + y[x].index + " is " + y[x].text);