我有各种 .img-drop-zones
,在放置文件时读取,我希望将其显示在放置它的特定放置区域的顶部,但是我该如何做得到它? $(this)
由于作用域而不起作用,我该如何传递它?
$('.img-drop-zone').on('drop', function(e){
var files = e.originalEvent.dataTransfer.files;
$.each(files, function(index, file){
p.file.read(file, function(content) {
//how can I get the img-drop zone here?
});
})
});
最佳答案
只需在外部作用域中声明一个附加变量,您可以在 $.each
闭包中引用该变量:
var $this = $(this);
$.each(..., function() {
// use $this here to refer to the img-drop-zone
});
当引用一个不是 jQuery 对象的对象时,更常见的是使用 self
或 that
。
关于javascript - $(this) 和范围 - 传递特定元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22232021/