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>
リンクボタンをクリックすると、「ドキュメントの準備ができました」というアラートが表示されますが、「送信が検出されました」というアラートは表示されません。