简体   繁体   English

检查jquery ui手风琴是否存在?

[英]check if jquery ui accordion exists?

is there an easy way to tell if a jquery accordion exists on the page...i am trying to dynamically build accordion based on selection that runs through $ajax, reads values from xml, and depending on the xml file selected builds strings the make up the accordion, and finally appends it. 是否有一种简单的方法来判断页面上是否存在jquery手风琴...我正在尝试根据运行$ ajax的选择动态构建手风琴,从xml读取值,并根据所选的xml文件构建字符串make手风琴,然后附加它。

I think that if the accordion already exists on the page, and the user selects another file, I am having trouble destroying the accordion, clearing the html, append the new string, then creating a new accordion... 我认为如果手风琴已经存在于页面上,并且用户选择了另一个文件,我就无法销毁手风琴,清除html,追加新的弦乐,然后创建一个新的手风琴......

like 喜欢

$("#accordion").accordion('destory').html('').append(string).accordion();

seems like if there is not already an accordion this idea breaks....thinking maybe i can just check?? 好像如果还没有手风琴这个想法打破....想想也许我可以检查?? thanks for any help to beginner! 感谢任何初学者的帮助!

I suspect that you could try checking .data() . 我怀疑你可以尝试检查.data()

var isAccordion = !!$("#accordion").data("ui-accordion");

Or, by checking the ui-accordion classname using .hasClass() which is added upon initialization. 或者,通过使用在初始化时添加的.hasClass()来检查ui-accordion类名。

var isAccordion = $("#accordion").hasClass("ui-accordion");

You could try with .length 你可以试试.length

Count the element using .length 使用.length计算元素

Or something like this 或类似的东西

if($('#accordion').length > 0) {
    // do something
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM