Home  >  Article  >  Web Front-end  >  Example introduction to the difference between JQuery and submit() in JS_jquery

Example introduction to the difference between JQuery and submit() in JS_jquery

WBOY
WBOYOriginal
2016-05-16 16:59:411158browse

ASP.NET's server control postback uses this piece of JS code:

Copy code The code is as follows:

var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit( );
}
}

The problem I encountered today is that I want to assign a value to one of the hidden fields before the server-side control posts back to pass the value to the server.

So I added an event using JQuery’s submit([[data],fn]) method, but found that it didn’t work.

I tried $("form:first").submit() and found that the event function can be triggered.

What’s going on? After checking the information, I found that the native function void submit() of js does not trigger the submit event. This is why there are
in the above code. Copy the code and the code is as follows:

if (< ;span style="color:#006600">!theForm.onsubmit || (theForm.onsubmit() != false)) {
...
}

That’s it.

So write the add event as
Copy the code The code is as follows:

$ ("form:first").get(0).onsubmit = function () {
...
};

That’s it.

In addition, events added using JQuery's submit([[data],fn]) can be triggered using $().submit().
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn