2013-03-02 41 views
0

我有一堆由class screen-cat-comment標識的DIV,我希望每個div都執行一個插件,該插件接收來自每個DIV的屬性值作爲參數。參考jQuery中的多個選擇器的屬性

<div class="screen-cat-comment" catId="1"></div> 
<div class="screen-cat-comment" catId="2"></div> 
<div class="screen-cat-comment" catId="3"></div> 

然後,選擇

$('.screen-cat-comment').fragment({ code: $(this).attr('catId') }); 

傳遞CATID來爲myplugin不工作 - 從當前的代碼,$(本).attr( 'CATID')返回undefined。有什麼辦法可以重寫這個選擇器來傳遞attr('catId')到插件嗎?

回答

1

在這方面this可能是window ......

$('.screen-cat-comment').each(function(){ 
    $(this).fragment({ code: $(this).attr('catId') }); 
});