asp.net - 在javascript中获取列表框的选定项目

标签 asp.net javascript vb.net

我在 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/

相关文章:

javascript - 使用 Javascript 从 S3 下载

asp.net-mvc - 在 ASP.NET MVC 中创建 Google Chart

javascript - Web请求检查服务器

javascript PhoneGap 条码扫描器太慢了

c# - 网页如何自动识别国家?

asp.net - .ASPX 页面如何获取其文件系统路径?

asp.net - jQuery 渗透测试

javascript - 数据从数据库中删除成功,但未刷新 AngularJS 中的当前页面

vb.net - 带坐标的 If 语句 (vb)

asp.net - Web应用程序中的Autofac,我应该将容器存储在哪里以便于访问?