Home Web Front-end JS Tutorial Introduction to the use of jquery events and functions_jquery

Introduction to the use of jquery events and functions_jquery

May 16, 2016 pm 05:21 PM
function declaration Binding events

1. Bind events

Method 1:

Use this method to add events to elements when the page loads
Copy code The code is as follows:

$("#myElement").click(function(){
alert($(this). text());
})

Method 2:

Same as 1, you can also add events to elements after the page is loaded, such as creating new DOM elements
Copy code The code is as follows:

$("#myElement").bing('click' ,function(){
alert($(this).text());
})

2. Function declaration and named function expression

Function declaration:
Copy code The code is as follows:

function myFun1() {
$("div").hide();
}

Call: myFun1();

Function expression:
Copy code The code is as follows:

var myFun2 = function(){
$("div").hide ();
}

Call: #("#myElement").click(myFun2);

Difference: The difference in calling time, Function declarations can be used anywhere, named function expressions can only be used after declaration
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Default parameters in C++ function declarations: a comprehensive analysis of their declaration and usage Default parameters in C++ function declarations: a comprehensive analysis of their declaration and usage May 02, 2024 pm 03:09 PM

Default parameters in C++ function declarations: a comprehensive analysis of their declaration and usage

What impact does the order of declaration and definition of C++ functions have? What impact does the order of declaration and definition of C++ functions have? Apr 19, 2024 pm 01:42 PM

What impact does the order of declaration and definition of C++ functions have?

What is the difference between C++ function declaration and definition? What is the difference between C++ function declaration and definition? Apr 18, 2024 pm 04:03 PM

What is the difference between C++ function declaration and definition?

C++ function declarations and definitions C++ function declarations and definitions Apr 11, 2024 pm 01:27 PM

C++ function declarations and definitions

C++ compilation error: function call does not match function declaration, how to solve it? C++ compilation error: function call does not match function declaration, how to solve it? Aug 22, 2023 pm 12:39 PM

C++ compilation error: function call does not match function declaration, how to solve it?

[[nodiscard]] in C++ function declarations: Demystifying the consequences of ignoring return values [[nodiscard]] in C++ function declarations: Demystifying the consequences of ignoring return values May 01, 2024 pm 06:18 PM

[[nodiscard]] in C++ function declarations: Demystifying the consequences of ignoring return values

Detailed syntax of C++ function declaration: from syntax analysis to standard usage analysis Detailed syntax of C++ function declaration: from syntax analysis to standard usage analysis Apr 30, 2024 pm 02:54 PM

Detailed syntax of C++ function declaration: from syntax analysis to standard usage analysis

Use jQuery to implement value change event binding of select elements Use jQuery to implement value change event binding of select elements Feb 24, 2024 am 08:51 AM

Use jQuery to implement value change event binding of select elements

See all articles