Home > Web Front-end > JS Tutorial > body text

About the submit() function in jQuery

巴扎黑
Release: 2017-06-29 10:28:23
Original
1298 people have browsed it

About submit() in jQueryFunction (Bind event handler or trigger event?)

I accidentally encountered one while typing code today It's a rather convoluted question (asked by a junior). I didn't understand it after thinking about it. I spent a long time on Baidu and Google in the morning, and read the English API before I finally understood it. Write it down now as a reminder to everyone. Without further ado, the code is as follows:


1  $('#myFormId').submit(function() { 
2      // submit the form 3      $(this).ajaxSubmit(); 
4      // return false,这样可以阻止正常的浏览器表单提交和页面转向 5      return false; 
6  });7  $('#myFormId').submit();
Copy after login

This section is similar to the code I encountered, when the program executes to the first line above The form submission event is not triggered, but the form is submitted when line 7 is executed. This led to the understanding of the following two functions:


1 $(selector).submit();2 $(selector).submit(fn);
Copy after login

After checking the API and searching on the Internet, I understood the whole story. The function in the first line above means to trigger the "submit" event of the selector-selected element, while the element in the second line means to bind the "submit" event processing function to the selector-selected element. In this way, we understand the meaning of the top code. The first line is to bind the processing function, and the seventh line of code is to trigger the event. OK, problem solved!

The following is the official API explanation in English. The official API explanation is reliable. I don’t understand the Chinese translation at all.

The three blue parts above are changes in different versions, and the ones circled in red explain their differences. English is relatively simple, so I won’t show off.

The above is the detailed content of About the submit() function in jQuery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!