如何将数据传递给jquery循环onBefore函数
我试图从 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于
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')
next
可能是一个 DOMElement。将其包装在 jquery 中:$(next).attr('id')
或只是执行next.id
.src
是元素的属性就像img
和tagName
是所有 DOM 元素的属性,所以我假设next
是一个img
。next
is probably a DOMElement. Wrap it in jquery:$(next).attr('id')
or just donext.id
.src
is a property of elements likeimg
andtagName
is a property of all DOM elements, so I assumenext
is animg
.