<%@ 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写的就不提交执行?
<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写的就不提交执行?
form1.hft1.value = "true";
<form id="form1" name="form1" runat="server" >再试看 javascript 提交
var ListBox1Id = "<%=this.ListBox1.ClientID%>";
alert(document.getElementById(ListBox1Id ).value);
<!-- -->在脚本区域不是注释,其作用是查看页面源代码的时候看不到脚本