gpt4 book ai didi

jquery - 将 live() 函数添加到 .jcarousel 方法

转载 作者:行者123 更新时间:2023-12-01 05:08:36 25 4
gpt4 key购买 nike

我正在尝试实现 jcarousel在我的网站上。默认的做法仅适用于 DOM 准备好时已经存在的数据。

就我而言,我尝试在来自搜索框的结果集(ul 和 li)上添加 jcarousel,这些搜索框是使用 AJAX 动态添加的。这意味着它必须以某种方式添加到 live() 才能工作(我认为)。我一直在尝试以不同的方式添加它,但没有成功。

live() 用于事件,而 jcarousel 则不是。在来到这里之前,我已经尝试了很多。这是我在 hxxp://jsfiddle.net/pcjUZ/15/上的一些尝试

// the default way of adding it
$('#results').jcarousel({
// Configuration goes here
vertical: true,
scroll: 2
});

// my way of trying to get it live()
// (which works on elements now and the ones added in the future)
// but mine doesnt work at all :/
$('#results').live("load", function(){
$(this).jcarousel({
// Configuration goes here
vertical: true,
scroll: 2
});
});

如果有人能帮助我,我将非常感激!提前致谢。

最佳答案

为什么不试试这个:Carousel with dynamic content loading via Ajax

查看该页面上的源代码,深入了解如何对 Ajax 加载的动态内容执行 jCarousel。

但是,如果它不是单独针对此 jCarousel 的 ajax 请求,那么我可能会将 jcarousel 插件附加到 .ajaxComplete() 事件处理程序上,而不是像正常情况那样附加到 document.ready() 上。

希望有帮助

关于jquery - 将 live() 函数添加到 .jcarousel 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3640259/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com