从 Accordion 更改功能访问 jQuery ui 对象
这应该很简单,但我似乎不知道该怎么做。我试图弄清楚 jQuery 手风琴中单击的部分是否有一个类。如果是这样,我们需要执行一个函数。到目前为止,我发现我可以在更改函数中使用以下内容检查正在执行的内容部分:
console.log(ui.newContent);
查看 Firebug 中的对象,我可以看到有一个 0 索引。在 Firebug 中单击 0 将其展开,显示它的对象属性之一列为“get classList”。但是,以下两项都无法访问它:
console.log(ui.newContent[0].classList);
console.log(ui.newContent[0].classList());
但是,我能够通过以下方式获取对象的 id:
console.log(ui.newContent[0].id);
因此,出于好奇,任何人都知道如何访问 classList,或者我只需要使用 id 作为选择器并再次获取对象,以便我可以在其上使用 .hasClass ?看起来有点浪费,但这是一个可能的解决方法。提前致谢!
This should be really simple, but I can't seem to figure out what to do. I'm trying to figure out if a clicked on section in a jQuery accordion has a class. If it does, we need to execute a function. So far, I've found that I can examine the content section being acted on using the following in the change function:
console.log(ui.newContent);
Looking at the object in Firebug, I can see there's a 0 index. Clicking on the 0 to expand it in Firebug reveals it has something listed as "get classList" as one of the object properties. However, neither of the following work to access this:
console.log(ui.newContent[0].classList);
console.log(ui.newContent[0].classList());
However, I was able to get the object's id via this:
console.log(ui.newContent[0].id);
So, out of curiosity, anyone know how to access the classList, or am I just going to have to use the id as a selector and get the object again so I can use .hasClass on it? Seems like a waste but its a possible workaround. Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
jQuery.hasClass() 应该适合你。在你的处理程序中:
jQuery.hasClass() should work for you. In your handler: