给ListBox添加双击事件示例代码

复制代码 代码如下:

  <!--创建一个JS调用button的click事件-->

  <script type="text/javascript">

  function JsListChangeItem() {

  document.getElementById("buttonShow").click();

  }

  </script>

  <!--创建一个隐藏的button,创建双击事件--->

  <asp:Button ID="buttonShow" runat="server" onclick="buttonShow_Click" Text="Button" style="display:none"/>

  <!--实现双击的listbox-->

  <asp:ListBox ID="listBox1" runat="server"Height="226px" Width="211px" AutoPostBack="True"></asp:ListBox>

  .cs

  

复制代码 代码如下:

  protected void Page_Load(object sender, EventArgs e)

  {

  listBox1.Attributes.Add("ondblclick", "JsListChangeItem()");//为listBox1添加双击事件。

  }