2011-07-28 42 views
0

嘿傢伙我創建了一個jquery插件,我試圖從表或行表選擇器中獲取錶行選擇器。從表或反之亦然獲取錶行對象

$("#table tr").myPlugin(); 

$("#table").myPlugin(); 

基本上在插件內我需要訪問表選擇器或行選擇器。所以在第一個版本中,我需要這個。

var table = $('#table'); 

或者在常規表格版本中,我需要這個。

var row = $('#table tr'); 

我該怎麼做?謝謝。

回答

0

從插件中,this.selector會爲您提供選擇器字符串或使用的選擇器方法,如.children(td)。 this.context將爲您提供選擇器的原始上下文。

$('tr').children('td'); 

//inside plugin 
this.selector; // "children(td)" 
this.context; // "tr" 
this.prevObject; //[tr] parent table row 

你可以玩不同的選擇在這裏:http://jsfiddle.net/MkCxD/

相關問題