我有一个名为(rowdata)的对象,在该对象中有两个由“\ n”分隔的连接值,我想在列表框中显示两个值。一个值一行,如何打破两个连接值并显示到列表框。
代码:
var myArray = [[rowdata]]; // assuming rowdata have two value separated by \n in localstorage
function populate(){
for(i=0;i<myArray.length;i++){
var select = document.getElementById("test"); //ID of the listboxt
select.options[select.options.length] = new Option(myArray[i][0], myArray[i][1]);
}
}
有办法吗?谢谢
答案 0 :(得分:0)
使用split:http://www.w3schools.com/jsref/jsref_split.asp
类似的东西:
function populate(){
for(i=0;i< rowdata.length;i++){
var select = document.getElementById("test"); //ID of the listboxt
var splitRow = rowData[i].split("\n");
select.options[select.options.length] = new Option(splitRow[0], splitRow[1]);
}
}