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

After ajax updates data, jquery and jq fail_jquery

WBOY
Release: 2016-05-16 18:09:20
Original
890 people have browsed it

Bind a click event to an element, but I encountered a problem that when I execute some ajax requests, the click event becomes invalid

For example, my paging is an ajax request, but it is generated when I click on the next page. There is no click event for element a

In fact, the reason is very simple

ajax loading content is an operation after $(document).ready(). At this time, when binding the function , the found element set does not include the content loaded by ajax, so there is no problem with the original one, and the later loaded ones are not bound

There are two solutions:

1. In the ajax request Rebind after success
2. Use the live method

Copy the code The code is as follows:



The two methods are suitable for different occasions

If it is to handle events, you can use live
If it is Some other processing methods do not support live and can only be rebound.
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