Solution to ineffective events bound to jquery _ jquery

Source: Internet
Author: User
The click events bound to jquery do not take effect. Many of you have encountered this problem. Let's solve it for you, if you want to bind a click event to jquery, you can refer to the following. The Code is as follows:
1. html:
Method functions referenced by 2.html in test. js:

The Code is as follows:


$ ("# Ceshisub"). bind ("click", function (){
Var a = 1;
A + = 1;
Alert ("ceshisub ");
});


The problem occurs when the click event button on the page does not respond, opening the js debugging window at var a = 1; the breakpoint hit by this line does not come in.
The solution is:
1. Add loading events to the above js functions:
The added code is as follows:

The Code is as follows:


$ (Function (){
$ ("# Ceshisub"). bind ("click", function (){
Var a = 1;
A + = 1;
Alert ("ceshisub ");
});
});


In this way, the binding event takes effect.
There are three js loading functions, except for the preceding

The Code is as follows:


$ (Function (){
Alert ("1st methods. ");
});


There are two other methods:

The Code is as follows:


Window. onload = function (){
Alert ("2nd methods. ");
}

$ (Document). ready (function (){
Alert ("3rd methods. ");
});


2. If the js loading function is not used to initialize the binding event, there is another method:
The js statement will be referenced

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.