如何检查jQuery UI插件是否附加到元素? [英] How to check if a jQuery UI plugin is attached to an element?

查看:105
本文介绍了如何检查jQuery UI插件是否附加到元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查jQuery UI插件是否附加到元素?例如,如果我加载.sortable小部件,它的存在如何确定?

How can I check to see if a jQuery UI plugin is attached to an element? For example, if I load up the .sortable widget, how can its presence be determined?

这个问题背后的目的是我希望能够切换.sortable在元素上。由于能够看到.sortable存在,我可以调用.sortable('destroy')将其删除。

The purpose behind this question is that I would like the ability to toggle .sortable on elements. With the ability to see that .sortable is present, I could then call .sortable('destroy') to remove it.

推荐答案

所有ui小部件都将其名称作为true附加到元素的容器数据中。 jqueryui还添加了一个数据过滤器表达式。

All ui widgets attach their name as true to the element's container data. jqueryui also adds a data filter expression.

var $elem = $('div.sortable-container:data(sortable)');
if ($elem.length){
  // $elem contains list of elements that have sortable widget attached
}

这篇关于如何检查jQuery UI插件是否附加到元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆