gpt4 book ai didi

jquery - document.forms[0].onsubmit 和 jQuery ("form").submit 之间的区别

转载 作者:行者123 更新时间:2023-12-01 03:50:51 25 4
gpt4 key购买 nike

为什么#1__doPostback时被调用(这个动态JavaScript函数是在HTML渲染时由ASP.NET自动创建的。我想当事件验证打开时) 被调用,但 #2 未被调用。然而,当单击按钮时,两者都会被调用?

#1

document.forms[0].onsubmit =
function() {
alert("called submit 1");
jQuery("#<%=DDLUCSAddress.ClientID %>").children("option").each(function() {
jQuery(this).remove();
});
};

#2

jQuery("form").submit(function() {
alert("called submit 2");
jQuery("#<%=DDLUCSAddress.ClientID %>").children("option").each(function() {
jQuery(this).remove();
});
});
<小时/>

渲染的 HTML - 如果我对此代码执行 Ctrl+K+D,由于空格,它会超出 Stack Overflow 的字符限制。如果您想查看其格式,请将其放入 Visual Studio 中并按 Ctrl+K+D

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<body>
<div id="sessionRefresh" style="display:none">
<script language="JavaScript" type="text/javascript" />
<form id="Form1" onsubmit="javascript:return WebForm_OnSubmit();" action="EditSampleDetails.aspx?LabAccessioningNumber=20120401-1&SampleTypeContext=247" method="post" name="Form1">
<div>
<script type="text/javascript" />
<script type="text/javascript" src="/WebResource.axd?d=EXaDJPTWpPG72bTbiKNh_OuYVox46idcF5L2FHTyi19FoknASLIR-iSOhjjdC3Xa0OCTSAQepXg5UpNN1TPkcREtvcQ1&t=634208598757546466" />
<script type="text/javascript" language="javascript" />
<script type="text/javascript" src="/WebResource.axd?d=4scrxOSLDbM-cgeLoXFnrTxM83c-T6NjCtRi_ghVZlXN0qjfjwNCtjtRWczFgkWux80g8Ip0p9JqPBJcPSlcT3N25CA1&t=634208598757546466" />
<script type="text/javascript" />
<div>
<div id="mainMenu" class="droplinetabs">
<table cellspacing="0" cellpadding="0" border="0">
<table class="uIBoxStacked" width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<tr>
<td class="uIBoxInternal" colspan="2">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td>
<div id="BxWizardTitle" style="border-color:LightSteelBlue;width:100%;">
<a href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00", "", true, "", "", false, true))'></a>
<a href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl01", "", true, "", "", false, true))'></a>
<a href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl02", "", true, "", "", false, true))'></a>
<a href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl03", "", true, "", "", false, true))'></a>
<table cellspacing="0" cellpadding="0" style="border-width:0px;">
<tbody>
<tr>
<td class="leftNavigationCell" style="vertical-align:top;">
<td>
<td valign="top">
<table cellpadding="5">
<tbody>
<tr>
<tr>
<td>
<table cellpadding="5">
<tbody>
<tr>
<tr>
<tr>
<td>
<script type="text/javascript" />
<table class="uIBoxStacked" width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<tr>
<td class="uIBoxInternal" colspan="2">
<table class="outerTableOfInputs" width="100%" cellspacing="0">
<tbody>
<tr>
<td>
<table class="tableOfInputs" width="100%" cellspacing="0">
<tbody>
<tr>
<td>
<div id="FullDataEntryEditor_UIBSampleInfo" style="border-color:LightSteelBlue;width:100%;">
<a href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("FullDataEntryEditor$ctl00", "", true, "", "", false, true))'></a>
<a href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("FullDataEntryEditor$ctl01", "", true, "", "", false, true))'></a>
<a href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("FullDataEntryEditor$ctl02", "", true, "", "", false, true))'></a>
<a href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("FullDataEntryEditor$ctl03", "", true, "", "", false, true))'></a>

<table>
<script type="text/javascript" />
<tbody>
<tr>
<tr>
<tr>
<tr>
<td>Additional Client Number</td>
<td>
<input id="FullDataEntryEditor_TxtAdditionalClientNumber" class="LIMSFormField" type="text" autocomplete="off" name="FullDataEntryEditor$TxtAdditionalClientNumber">
</td>
</tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<table class="saveCancelDeleteOuter" width="100%" cellspacing="0">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td>
<input id="EditObjectId986257676" type="hidden" value="" name="EditObjectId986257676">
<input id="CommandName986257676" type="hidden" value="" name="CommandName986257676">
<table class="uIBoxStacked" width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<tr>
<tr>
<td class="uIBoxInternal" colspan="2">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td>
<div id="FullDataEntryEditor_NMNotes_List_ListBox" style="border-color:LightSteelBlue;width:100%;">
<a href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("FullDataEntryEditor$NMNotes$List$ctl00", "", true, "", "", false, true))'></a>
<a href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("FullDataEntryEditor$NMNotes$List$ctl01", "", true, "", "", false, true))'></a>
<a href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("FullDataEntryEditor$NMNotes$List$ctl02", "", true, "", "", false, true))'></a>
<a href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("FullDataEntryEditor$NMNotes$List$ctl03", "", true, "", "", false, true))'></a>
<table id="FullDataEntryEditor_NMNotes_List_ListGrid" cellspacing="0" cellpadding="4" border="1" style="width:100%;border-collapse:collapse;" rules="all">
<tbody>
<tr class="columnHeader">
<tr style="background-color:Yellow;">
<td>
<a href="javascript:listCustomPostback(986257676,'Edit',129285);">bbbbbbbbbbbbbb</a>
</td>
<td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<div id="pdfDisplay"></div>
<script language="javascript" type="text/javascript" />
</td>
</tr>
<tr>
</tbody>
</table>
<script type="text/javascript" />
<input id="FullDataEntryEditor_HiddenSampleType" type="hidden" value="247" name="FullDataEntryEditor$HiddenSampleType">
<input id="FullDataEntryEditor_HiddenAJAXUCSAddressValue" type="hidden" value="7533" name="FullDataEntryEditor$HiddenAJAXUCSAddressValue">
<input id="FullDataEntryEditor_HiddenAJAXUCSAddressText" type="hidden" value="[7533] A1's Primary address, a1_primary_address, madison wi, usa 53719" name="FullDataEntryEditor$HiddenAJAXUCSAddressText">
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<table class="saveCancelDeleteOuter" width="100%" cellspacing="0">
<script type="text/javascript" />
<script type="text/javascript" />
<script type="text/javascript" />
</form>
<table class="copyright" align="center">
</body>
</html>

最佳答案

  • 第一个 document.forms[0].onsubmit 不是 jQuery。它分配给文档中的第一个表单。如果您单击第一个表单上的提交按钮,它就会被触发
  • 第二个 jQuery("form").submit 是 jQuery,但分配给文档中的所有 form。如果您单击文档中每个表单上的提交按钮,它就会被触发

关于jquery - document.forms[0].onsubmit 和 jQuery ("form").submit 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8793594/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com