Related knowledge points about jQuery events

jacklove
Release: 2018-05-08 11:39:30
Original
1266 people have browsed it

jQueryis specially designed forevent processing, which is particularly important in js, so this article will learn about jQuery events.

jQuery event function

jQuery event handling method is the core function in jQuery.

Event handlers refer to methods that are called when certain events occur in HTML. The term "triggered" (or "inspired") by an event is often used.

Usually put the jQuery code in the event handling method in thepart:

Example

    
  

This is a heading

This is a paragraph.

This is another paragraph.

Copy after login

Try it yourself

above In the example, when the click event ofbuttonis triggered, a function will be called:

$("button").click(function() {..some code... } )

This method hides all

elements:

$("p").hide();

in a separate file Functions

If your website contains many pages and you want your jQuery functions to be easy to maintain, put your jQuery functions into separate .js files.

When we demonstrate jQuery in the tutorial, we add the function directly into thesection. However, it would be better to put them in a separate file, like this (referencing the file through the src attribute):

Example

   
Copy after login

jQuery Name Conflict

jQuery uses the $ symbol as jQuery'sIntroductionway.

Some functions in other JavaScript libraries (such as Prototype) also use the $ symbol.

jQuery uses a method called noConflict() to solve this problem.

var jq=jQuery.noConflict(), helps you use your own name (such as jq) instead of $ sign.

Conclusion

Since jQuery is specifically designed to handle HTML events, your code will be more appropriate and easier to maintain when you follow these principles:

Put Place all jQuery code in event handlers

Place all event handlers in document ready event handlers

Put jQuery code in separate .js files

If there is a name conflict, rename the jQuery library

This article provides a relevant understanding of jquery events. For more learning materials, please pay attention to the php Chinese website.

Related recommendations:

SQL Server - RDBMS related knowledge

Related knowledge points about SQL NULL values

Explanation of knowledge related to SQL Date function

The above is the detailed content of Related knowledge points about jQuery events. 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 Recommendations
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!