$(this)jQuery插件参数中的选择器指针

时间:2014-03-12 13:11:01

标签: javascript jquery jquery-plugins

对于许多选择器设置选项:

$('#fileupload1, #fileupload2, #fileupload3').dropZone(
    'option',
    {
        url: '/path/to/upload/handler.json',
        dropZone: $(this).find('.dropzone') //Does not work!!!
    }
);

为什么呢?请帮忙!

1 个答案:

答案 0 :(得分:2)

因为this没有引用选择器中的元素。

var $els = $('#fileupload1, #fileupload2, #fileupload3');
$els.dropZone('option', {
    url: '/path/to/upload/handler.json',
    dropZone: $els.find('.dropzone') //Does not work!!!
});

如果您想将个别dropzone传递给所有3个元素,请使用每个循环

$('#fileupload1, #fileupload2, #fileupload3').each(function () {
    $(this).dropZone('option', {
        url: '/path/to/upload/handler.json',
        dropZone: $(this).find(.'dropzone') //Does not work!!!
    });
})
相关问题