How Should jquery set the onclick event for changing the button input?

Source: Internet
Author: User
To dynamically change The onclick function in the previous page. I have tried many methods and have not made them. The following are examples of failures. If you need them, refer to how jquery sets the onclick event of the button input? For example, there is a button at the beginning: This line of code is generated in the background of the program, and Discuz! In the same way as in the source code of the NT Forum, all things and scripts on the page are generated by the background code .. then use jquery. load ajax to the page .. others except ie8 cannot be displayed .. other browsers are normal. now the problem is: to dynamically change The onclick function in the previous page button. I tried many methods and did not make them. The following are examples of failure:
1. JavaScript code:

The Code is as follows:


$ ("# Prebt "). unbind ("onclick", function () {var p = $ ("# nextbt "). parent (); $ ("# nextbt "). remove ();
P. append ("")});
JavaScript code:
$ ("# Prebt"). removeAttr ("onclick ");
$ ("# Prebt"). attr ("onclick", "ToPage (4 )");
Or:
$ ("# Prebt"). attr ("onclick ","");
$ ("# Prebt"). attr ("onclick", "ToPage (4 )");


2. JavaScript code:

The Code is as follows:


$ ("# Prebt"). removeAttr ("onclick ");
$ ("# Prebt"). click (function () {ToPage (4)}); // This sentence will lead to an endless loop... I don't know what's going on ..
// My paging function... In this way, data is constantly jumping. How can this problem be solved?


There is really no way to do it. I can only post related requests on the Internet. A friend asked me if I want the following results:

The Code is as follows:


$ ("# Prebt"). unbind ("onclick ");
$ ("# Prebt"). bind ("onclick", "ToPage (4 )");


In fact, the effect I want is the same as above, but the above method is similar to my original effect, and cannot be executed, and cannot be bound at all.
Another enthusiastic user gave me a code example, saying it was helpful to me. The details are as follows:
XML/HTML code:

The Code is as follows:






Untitled document

Related Article

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.