查找在其上初始化了jquery小部件的元素 [英] Find elements which have jquery widgets initialized upon them

查看:88
本文介绍了查找在其上初始化了jquery小部件的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 jQuery-File-Upload 小部件(虽然我相信这个问题可以推广到任何jQuery小部件)。 API 指示用户使用<$ c初始化窗口小部件$ c> fileupload 方法,因此:

I am using the jQuery-File-Upload widget (although I believe this question can generalize to any jQuery widget). The API instructs the user to initialize the the widget using the fileupload method, thus:

$('#fileupload').fileupload();

我的问题是:在不知道ID的情况下,如何找到 #fileupload (以及任何其他已经调用了 .fileupload()的元素?

My question is: Without knowing IDs, how can I find #fileupload (and any other elements which have had .fileupload() called upon them?

推荐答案

jQuery文件上传使用了引擎盖下的jQuery UI小部件工厂,并且已知该工厂使用 data()

jQuery File Upload uses the jQuery UI widget factory under the hood, and that factory is known to register the widgets instances with the elements they extend using data().

因此,您可以使用 filter()并写下如下内容:

Therefore, you can use filter() and write something like:

// Restrict ancestor if you can, $("*") is expensive.
var uploadified = $("#yourAncestor *").filter(function() {
    return $(this).data("fileupload");
});

更新: 从jQuery UI 1.9开始, data()键成为小部件的完全限定名称,点用短划线替换。因此,上面的代码变为:

Update: From jQuery UI 1.9 onwards, the data() key becomes the widget's fully qualified name, with dots replaced by dashes. Therefore, the code above becomes:

var uploadified = $("#yourAncestor *").filter(function() {
    return $(this).data("blueimp-fileupload");
});

1.9中仍然支持使用非限定名称但不推荐使用,支持将在1.10中删除。

Using the unqualified name is still supported in 1.9 but is deprecated, and support will be dropped in 1.10.

这篇关于查找在其上初始化了jquery小部件的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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