我在 asp.net 中有两个列表框。单击一个按钮,我想加载一个列表框,其中包含另一个框中所选项目的元素。问题是这必须在客户端完成,因为单击按钮时我不允许它提交。我想调用一个 javascript 函数 onselectedindexchange 但那是服务器端。有任何想法吗?我应该更清楚吗?
解决方案
enter code here
function Updatelist() {
var sel = document.getElementById('<%=ListBox1.ClientID%>')
var lst2 = document.getElementById('<%=ListBox2.ClientId %>')
var listLength = sel.options.length;
var list2length = lst2.options.length;
for (var i = 0; i < listLength; i++) {
if (sel.options[i].selected) {
//lst2.options.add(sel.options[i].text);
lst2.options[list2length] = new Option(sel.options[i].text);
list2length++;
}
}
}
最佳答案
尝试:
//onclick for button calls this function
function Updatelist() {
var sel = document.getElementbyId("list1");
var listLength = sel.options.length;
for(var i=0;i<listLength;i++){
if(sel.options[i].selected)
document.getElementById("list2").add(new Option(sel.options[i].value));
}
关于asp.net - 在javascript中获取列表框的选定项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/860511/