2013-04-03 23 views
2

我正在製作一個jQuery插件,如何在當前設置中找到.selected元素?使用jQuery在當前設置中查找元素

$('a').selected(); // initial set `a` 

$.fn.selected = function() { 

return $('.selected', this); 
// produces `a .selected` but I want to find `a.selected` 

} 

回答

1

您應該使用.filter()代替:

return this.filter('.selected'); 

...作爲jQuery的原型擴展功能($.fn.selected,你的情況)內this指的是jQuery對象本身。

+0

當然,謝謝! – firedev