jQuery live()可与jQuery 1.8.3&以下,但不适用于1.9.1或2.0 [英] jQuery live() works with jQuery 1.8.3 & below but not with 1.9.1 or 2.0

查看:130
本文介绍了jQuery live()可与jQuery 1.8.3&以下,但不适用于1.9.1或2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 http://ajax .googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js 已有一段时间了,一切都很好,但是1.8.3已经很老了,所以我决定移至最新的jQuery.突然有些事情停止了工作: Quicksand插件和我自己的jQuery代码的一部分(在每个滑块).

I've been using http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js for a while now and everything has been fine, but 1.8.3 got quite old so I've decided to move to the latest jQuery. And suddenly a few things stopped working: Quicksand plugin and part of my own jQuery code (that shows additional data under every slide of a slider).

您能帮我弄清楚出什么问题吗?还是不值得转移到1.8.3以上的jQuery版本?检查Jsfiddle.

Can you help me figuring out what's wrong? Or maybe it's not worth moving to jQuery versions above 1.8.3? Check the Jsfiddle.

HTML:

<a href="#" class="show" data-show="first">SHOW</a>
<a href="#" class="show" data-show="second">SHOW</a>

<div id="first">First paragraph.</div>
<div id="second">Second paragraph</div>

JS:

jQuery(".show").live("click", function (e) {
    var slide = '#' + jQuery(this).data('show');
    jQuery(slide).slideToggle();
    e.preventDefault();
});

CSS:

div { display: none; }

这是一个有效的jsfiddle: http://jsfiddle.net/ABrna/

Here's a working jsfiddle: http://jsfiddle.net/ABrna/

尝试将jQuery更改为1.9.1或2.0,然后单击运行".脚本停止工作.为什么?

Try changing jQuery to 1.9.1 or 2.0 and hit Run. Script stops working. Why?

推荐答案

.live()方法自jQuery 1.7起已被弃用,并已从1.9中删除.

The .live() method has been deprecated since jQuery 1.7 and has been removed in 1.9.

http://jquery.com/upgrade-guide/1.9/#live-删除

这篇关于jQuery live()可与jQuery 1.8.3&amp;以下,但不适用于1.9.1或2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆