jQuery Click 事件不适用于 jCarousel

发布于 2024-10-09 11:40:45 字数 355 浏览 0 评论 0原文

这个问题的标题部分正确。单击事件适用于我在加载时显示的三个初始轮播项目。单击上一个或下一个后,新项目不会触发单击事件,如果 3 个原始项目移出屏幕,也不会触发单击事件。

我正在使用最新版本的 jquery,默认显示 3 项。我的目标是能够访问锚标记中包含的每个轮播项目内的文本。每个轮播项目都有一个图像和围绕标题的锚标记。

$('li').click(function() { 
    var clickedItem = $(this).attr('class');
    console.log(clickedItem);
});

如果我能让这个简单的点击事件发生在其他元素上,一切都会很好。有什么想法吗?

The title to this question is partially true. The click events work for the three initial carousel items i display on load. Once you click previous or next the new items don't trigger the click event and neither do any of the 3 original items if they get moved off the screen.

I'm using the latest version of jquery and am displaying 3 items by default. My objective is to be able to access text inside each carousel item that is contained in an anchor tag. Each carousel item has an image, and an anchor tag surrounding a title.

$('li').click(function() { 
    var clickedItem = $(this).attr('class');
    console.log(clickedItem);
});

If i can get this simple click event to occur on the other elements all will be good. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

星星的軌跡 2024-10-16 11:40:45

试试这个:

$("#carousel").delegate("li", "click", function() {
    var clickedItem = $(this).attr('class'); 
    console.log(clickedItem);
});

Try this:

$("#carousel").delegate("li", "click", function() {
    var clickedItem = $(this).attr('class'); 
    console.log(clickedItem);
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文