我正在尝试使用 jQuery 处理元素的submit
事件。form
$("form").bind("submit", function() {
alert("You are submitting!");
});
这在表单提交时永远不会触发(作为回发的一部分,例如当我单击按钮或链接按钮时)。
有没有办法使这项工作?我可以附加到触发提交的单个元素的事件,但这不太理想 - 有太多的可能性(例如带有 autopostback=true 的下拉列表、键盘快捷键等)
更新:这是一个最小的测试用例 - 这是我的 aspx 页面的全部内容:
<%@ page language="vb" autoeventwireup="false" %>
<!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>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:scriptmanager id="ScriptManager" runat="server" enablepartialrendering="true">
<scripts>
<asp:scriptreference path="/Standard/Core/Javascript/Jquery.min.js" />
</scripts>
</asp:scriptmanager>
<p>
<asp:linkbutton id="TestButton" text="Click me!" runat="server" /></p>
</div>
</form>
<script type="text/javascript">
$(document).ready(function() {
alert("Document ready.");
$("form").submit(function() {
alert("Submit detected.");
});
});
</script>
</body>
</html>
单击链接按钮时,我收到“文档准备就绪”警报,但没有“检测到提交”。