如何从插件被调用的集合(不是DOM本身)中移除没有id
属性的元素?从jQuery选择中删除没有ID的元素?
<span id="id737293" class="attach"></span>
<div class="attach"></span>
jQuery的调用和插件:
$('.attach').attach();
(function($) {
$.fn.attach = function(options) {
// Remove elements (without id) on which the plugin was invoked
var valid = ???;
// Loop each valid element (with id attribute) and process
valid.each(function() {
});
return this; // Maintain chainability
};
})(jQuery);
辉煌。据我了解,这只会筛选选择而不会影响DOM或可链接性,对吗? – gremo 2012-01-27 14:29:17
@Gremo是的,只有'valid'变量将包含元素的过滤列表。 – 2012-01-27 14:55:52
这很好,但过滤器函数应该返回有效的元素(因此返回this.id)...因为jsfiddle显示红色的无效元素;) – gremo 2012-01-27 15:03:04