2010-07-21 39 views

回答

3

檢查下面的例子中,與值更改textboxasp listbox

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <script type="text/javascript" language="javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <asp:ListBox ID="ListBox1" runat="server" Width="50px" Height="100px" 
      SelectionMode="Multiple"> 
      <asp:ListItem Value="One">1</asp:ListItem> 
      <asp:ListItem Value="Two">2</asp:ListItem> 
      <asp:ListItem Value="Third">3</asp:ListItem> 
      <asp:ListItem Value="Four">4</asp:ListItem> 
      <asp:ListItem Value="Five">5</asp:ListItem> 
     </asp:ListBox> 
     <br /> 
     <asp:TextBox ID="text1" runat="server"></asp:TextBox> 
    </div> 
    </form> 
</body> 
</html> 

<script type="text/javascript"> 
    $('#ListBox1').click(function() { 
     $("input#text1").val($("#ListBox1 option:selected").val()); 
    }); 
</script> 
+1

這是錯誤的點擊,你需要ASP控制的clientID的,以便在javascript與它合作 – DWolf 2012-12-14 18:46:38