如何杀死/重置正在运行的jQuery插件? [英] how to kill/reset a running jquery plugin?

查看:72
本文介绍了如何杀死/重置正在运行的jQuery插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很好的幻灯片插件.独自...

I have a slideshow plugin which works fine. Alone...

我在一页上有3个不同的按钮.他们都调用同一个jQuery幻灯片插件,并将具有不同图像的幻灯片加载到同一个分隔器中(ID为"slideshow")

I have 3 different buttons on one page. They all call the same jQuery slideshow plugin and load the slideshow with different images into the same divider (with id="slideshow")

我每次都会在#slideshow中删除幻灯片及其元素,然后再用新图像加载新的幻灯片.

I remove the slideshow and it's elements from the #slideshow every single time before I load the new slideshow with the new images.

一切正常,除了我单击按钮的次数越多,整个事情就越混乱,因为每次打开插件都会使插件困惑,从而无法显示哪些图像.

It would all work fine except that the more times I click on the buttons the messier the whole thing gets because the plugin is opened every single time and the plugin gets confused which images to show.

我的问题是.如何完全杀死正在运行的插件,以便可以从头开始加载新插件.我尝试了empty(),die(),remove(),detach()API,但没有成功.

My question is. How can I completely kill a running plugin so the new one can load from the beginning. I tried empty(), die(), remove(), detach() APIs without successs.

还有其他方法吗?

谢谢.

http://muttley.freewebspace.com/slideshow/

推荐答案

不幸的是,如果插件本身不支持该功能,则没有通用的销毁插件的方法.您可能必须删除实际上在其上调用了插件的元素,然后再次创建它:

Unfortunately there isn't a common way to destroy plugins on an element, if the plugin itself doesn't support it. You will probably have to remove the element you actually called the plugin on and create it again:

var oldDiv = $('#slideshow');
var parent = oldDiv.parent();
oldDiv.remove();
parent.append($('<div>').attr('id', 'slideshow'));
// Initialize slideshow here again

// Untested but shorter way:
$('#slideshow').replaceWith($('<div>').attr('id', 'slideshow'));

这篇关于如何杀死/重置正在运行的jQuery插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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