简体   繁体   English

简单的jQuery插件-参考错误?

[英]Simple jQuery plugin - reference error?

I'm writing simple jQuery plugin and it should search all .camp_row on the page and everywhere when it find .log.active , it should change its border. 我写简单的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();

The problem is, it wor on only one result. 问题是,它只在一种结果上令人担忧。 I think that's because "that" refer to a specific .log.active' but no all .log.active . 我认为这是因为“那个”是指特定的.log.active'而不是所有.log.active

If I understand the question, you should pass the selector in constructor, then: 如果我理解这个问题,则应在构造函数中传递选择器,然后:

$.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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM