jquery动态添加元素事件失效问题解决方法_jquery

WBOY
Release: 2016-05-16 16:47:11
Original
1555 people have browsed it

今天在写JQUERY时遇到个问题:当使用脚本动态添加元素xxx时,但事件$(".x .y").click(function)...失效问题。

刚开始网上找到了用live函数,方法如下:

事件绑定:$(".x .y").click(function) 需改为:

复制代码代码如下:

$(".x .y").live('click',function);

但是由于1.8版本后live这种方法不再支持,所以需要用下述jquery中on方法解决脚本动态添加元素:
复制代码代码如下:

$(".y").on('click','.x',function);
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
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!