选择插件以外的元素链接此关键字

时间:2011-12-04 10:02:00

标签: javascript jquery

我在创建一个链接问题的插件时,我想选择THIS元素之外的元素,例如

return $this.each(function() {
    $('body $left .filter-wrapper input[type=checkbox]', document).change(function() {
        alert('changed');// I want to break out side the scope how do i do that
        and select element that aren't in $('mygrid').Grid()
        // ive tried $('body $left .filter-wrapper input[type=checkbox]') 
        // that doesn't work either
    }).find(this).filter(....).click(function() {
        // this refers to mygrid which is what i want but the ubove code doen't work 
    }).find(....).click(function(){
        // do more stuff here
    }).bind('....')
});

$( 'mygrid')。网格()

1 个答案:

答案 0 :(得分:2)

请检查问题的格式,这很难阅读。

如果你想选择$(this)之外的元素,你可以考虑像平常一样选择它们:

$("div.clickable").click(function() {
    $(this).hide();
    $("div.outsidethis").doSomething();
});

或者,您可以使用$ .proxy()将当前上下文传递给您的方法:

$("div.clickable").click($.proxy(function(){
    // this is now NOT div.clickable but whatever this was before
}, this));

http://api.jquery.com/jQuery.proxy/