[英]Simple jQuery plugin - reference error?
我寫簡單的jQuery插件,它應該搜索所有.camp_row
在頁面上到處都當它發現.log.active
,就應該改變其邊界。
$.fn.filtruj = function(){
$(this).on('click', function(){
var that = $(this);
$('.camp_row').each(function(){
$(this).find(that).css('border','10px solid orange');
});
})
}
$('.log.active').filtruj();
問題是,它只在一種結果上令人擔憂。 我認為這是因為“那個”是指特定的.log.active'
而不是所有.log.active
。
如果我理解這個問題,則應在構造函數中傳遞選擇器,然后:
$.fn.filtruj = function(selector){
$(this).on('click', function(){
var that = $(this);
$('.camp_row').each(function(){
$(this).find(selector).css('border','10px solid orange');
});
})
}
$('.log.active').filtruj('.log.active');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.