如何将数据传递给jquery循环onBefore函数

发布于 2024-12-21 03:38:01 字数 509 浏览 4 评论 0原文

我试图从 jquery 循环的 onBefore 函数中可用的“curr”或“next”对象获取数据,以便我可以使用 ajax 将其传递给 PHP 脚本来填充 opts.addSlide();

理想情况下,我想使用 data() 属性,但我什至很难使用 .attr()

在文档中,这有效:

var currentImageNum = parseInt(next.src.match(/beach(\d)/)[1]);

而且我已经看到它有效

var tag = next.tagName.toLowerCase();

,所以为什么我不能使用它或类似的东西

var mydata = next.attr('id');

要获取幻灯片的 ID,

我得到的错误是 Uncaught TypeError: Object # has no method 'attr'

I'm trying to get data from either the 'curr' or 'next' object available in jquery cycle's onBefore function so I can pass it to a PHP script with ajax to populate opts.addSlide();

Ideally i'd like to be use the data() attribute but i'm struggling even to use .attr()

In the documentation, this works:

var currentImageNum = parseInt(next.src.match(/beach(\d)/)[1]);

and i've seen this working

var tag = next.tagName.toLowerCase();

so why can't I use this or something similar

var mydata = next.attr('id');

to get the ID of the slide

the error I get is Uncaught TypeError: Object # has no method 'attr'

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

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

发布评论

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

评论(2

情场扛把子 2024-12-28 03:38:01

由于 next 是一个 DOM 元素,您应该首先将其转换为 jQuery 对象,然后您可以在其上调用 jQuery api。试试这个

$(next).attr('id')

Since next is a DOM element you should first convert it into jQuery object and then you can call jQuery apis on it. Try this

$(next).attr('id')

两人的回忆 2024-12-28 03:38:01

next 可能是一个 DOMElement。将其包装在 jquery 中:

$(next).attr('id') 或只是执行 next.id

.src 是元素的属性就像 imgtagName 是所有 DOM 元素的属性,所以我假设 next 是一个 img

next is probably a DOMElement. Wrap it in jquery:

$(next).attr('id') or just do next.id

.src is a property of elements like img and tagName is a property of all DOM elements, so I assume next is an img.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文