<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MyListBoxDoubleClickEvent.aspx.cs" Inherits="事件处理.MyListBoxDoubleClickEvent" %><!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 language="vbscript" type= "text/vbscript">
        option explicit
        sub ListBox1_ondblclick()
           Form1.hft1.Value = "true"
           form1.submit()
         end sub        
    </script>
   -->
   --下面的不能执行为何??????
   <script language="javascript" type="text/javascript">
       function ListBox1_ondblclick()
       {
          form1.hft1.Value = "true";
         
          alert(form1.hft1.Value);
          document.form1.submit();
       }
    </script>
</head>
<body>
    <form id="form1" runat="server" >
    <div>
        <asp:ListBox ID="ListBox1" runat="server" Height="125px" Width="136px">
            <asp:ListItem Selected="True" Value="1111"></asp:ListItem>
            <asp:ListItem Value="22222"></asp:ListItem>
            <asp:ListItem Value="3333"></asp:ListItem>
        </asp:ListBox><asp:Label ID="Label3" runat="server" Text="Label" Width="187px"></asp:Label>
        <asp:HiddenField ID="hft1" runat="server" Value="111" />
    
    </div>
    </form>
</body>
</html>
asp.net编写的
为何用vbscrip写的能执行,而javascr写的就不提交执行?

解决方案 »

  1.   

    try:
    form1.hft1.value = "true"; 
      

  2.   

    <head runat="server"> 变 <head> 同时增加
    <form id="form1" name="form1" runat="server" >再试看 javascript 提交
      

  3.   

    function执行了吗?是都没有执行还是只有submit没执行?
      

  4.   

    经过楼上提醒function没执行,为何?
      

  5.   

    1、Value 改: value 2、服務端的ID 不一定於客戶端的一致。可Try:
    var ListBox1Id = "<%=this.ListBox1.ClientID%>";
    alert(document.getElementById(ListBox1Id ).value);
      

  6.   

    貌似VBScript在前面已经submit了,轮不到javascript了
    <!--  -->在脚本区域不是注释,其作用是查看页面源代码的时候看不到脚本