【问题标题】:$(this) selector pointer in jQuery plugin parametersjQuery 插件参数中的 $(this) 选择器指针
【发布时间】:2014-03-12 13:11:00
【问题描述】:

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

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

为什么?请帮忙!

【问题讨论】:

  • 你能解释一下你的问题吗?
  • 自我解释。

标签: javascript jquery jquery-plugins


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-24
    • 1970-01-01
    • 1970-01-01
    • 2014-07-12
    • 2011-07-26
    • 2011-03-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多