看到代码即可明白小弟意思。点击按钮后发现选项任然存在,(查看html代码也在)不知道其中什么机制。要实现此功能如何做。谢谢!<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<script type ="text/javascript" >
    function del(){
        var sel=document.getElementById("sel");
        var len=sel.options.length;
         alert(len);
        for(var i=len-1;i>=0;i--){           
            sel.remove(i); 
        }
    }    
</script>
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ListBox ID="sel" runat="server" Height="104px" Width="176px">
            <asp:ListItem Value="a">1</asp:ListItem>
            <asp:ListItem Value="b">2</asp:ListItem>
        </asp:ListBox>
        <asp:Button ID="btn" runat="server" Text="Button"  OnClientClick ="del();"/>
        </div>
    </form>
</body>
</html>

解决方案 »

  1.   

    还有补充,这样如果成功了,那么着客户端js添加进去的options  后台服务器端是否能取到呢?
    谢谢
      

  2.   

    <asp:Button ID="btn" runat="server" Text="Button"  OnClientClick ="del();return false;"/>
      

  3.   


    function SelectClear(obj)
    {
    var tLength=obj.options.length;
    for (var i=0;i<tLength;i++)
    {
    obj.options.remove(0);
    }
    }给你一段代码
      

  4.   

    注意是这个哦 
    obj.options.remove(0);
      

  5.   

    OnClientClick 
    需要有返回值的,默认是return true
    因为你应用的是服务器控件。
    及时你删除成功那么也会重新刷新下页面(还原了)
    如果return false则不会进入服务器段
      

  6.   

    其实我遇到的问题是这样的:一个页面  点击一个label 此时在session中把listbox的value保存  然后 open一个画面  在open的画面中通过session中的value查询数据  然后open页面关闭 此时刷新父页面中的listbox使它等于子画面中查询出的数据。我原先的思路是  子画面关闭的时候调用父换面的JavaScript  :function SelectClear(obj)
    {
        var tLength=obj.options.length;
        for (var i=0;i<tLength;i++)
        {
            obj.options.remove(0);
        }
    }
     结果 无法实际操作服务器控件listbox
    所以发问。因为比较急  后来是这样解决的:子画面关闭 调用父画面JavaScript:这里随便写个方法 触发点击服务器控件  比如button 然后再cs代码中操作添加或删除listbox项目。
    具体是参照了别人的做法:http://zhidao.baidu.com/question/88603512.html?fr=ala0谢谢大家。有碰到类似问题的初学者也可参考。