在js中怎么获得ListBox选中的值

解决方案 »

  1.   

     <script   language= "javascript "   > 
                  function   Display() 
                  { 
                            var   listBox   =   document.getElementById( "ListBox1 "); 
                            alert(listBox.options[listBox.selectedIndex].value); 
                            document.getElementById( "TextBox1 ").innerText   =     listBox.options[listBox.selectedIndex].value; 
                  } 
            </script> 
    </head> 
    <body> 
            <form   id= "form1 "   runat= "server "> 
            <div> 
                    <asp:ListBox   ID= "ListBox1 "   runat= "server "   onclick   = "Display(); "> 
                        <asp:ListItem   Selected   = "true "   Value= "1 "   > sfsfsfsf </asp:ListItem>
                        <asp:ListItem   Value= "2 "   > s34242 </asp:ListItem> 
                        <asp:ListItem   Value= "3 "> sdf2233 </asp:ListItem> 
                    </asp:ListBox> 
                    <asp:TextBox   ID= "TextBox1 "   runat= "server "> </asp:TextBox> </div> 
            </form> 
    </body> 
    </html>
    http://topic.csdn.net/u/20070605/16/d271b09f-272a-42dd-8c1f-2d089d85aadb.html
      

  2.   

     var list = document.getElementById('<%=ListBox1.ClientID %>');  
     for(var i=0;i<list.options.length;i++){
       if(list[i].checked){
       //  选中
       }}
      

  3.   


    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %><!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">
        <title>无标题页</title>    <script src="jquery-1.3.2-vsdoc.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function(){
             
                $("#ListBox1").click(function(){
                    alert($("#ListBox1").val());
                })
            });
        </script>
    </head>
    <body>
       
        <form id="form1" runat="server">
        <div>
         <asp:ListBox ID="ListBox1" runat="server">
            <asp:ListItem>
                1
            </asp:ListItem>
               <asp:ListItem>
                2
            </asp:ListItem>
        </asp:ListBox>                
        </div>
        </form>
        
    </body>
    </html>