【发布时间】:2019-09-28 06:39:22
【问题描述】:
我很困惑,我不知道如何访问父 div。让我总结一下!
实际上我有多个dropzone,我使用类'.abc'初始化 在每个 dropzone 上方都有输入,我在其中放置图像名称以进行上传。这是我的代码
$('.kt_dropzone_1').dropzone({
url: base_url + 'product/uploadPic', // Set the url for your upload script location
paramName: "file", // The name that will be used to transfer the
maxFiles: 1,
maxFilesize: 5, // MB
addRemoveLinks: true,
accept: function (file, done) {
done();
},
success: function (file, response) {
alert($(this).attr('data-abc')); // undefined
alert($(this).parent().parent.html()); // undefined
},
});
这里是 html,它在循环中,所以考虑它是多个
<input type="hidden" class="img-upload" name="old" value=""/>
<div class="col-md-12 pull-left">
<div class="dropzone dropzone-default kt_dropzone_1">
<div class="dropzone-msg dz-message needsclick">
<h3 class="dropzone-msg-title">Drop files here or click to upload.</h3>
<span class="dropzone-msg-desc">This is just a demo
dropzone. Selected files are <strong>not</strong>
actually uploaded.</span>
</div>
</div>
</div>
我尝试使用自定义属性来传递输入 id 动态仍然不起作用 我不知道如何获取当前 div 对象以访问父 html 或输入或 div
【问题讨论】:
-
在匿名回调函数
this的范围内不再引用父级 - 您可以尝试将函数绑定到父级以访问this -
@RamRaider 怎么样?
-
不确定这是否可行,因为我不知道
this在dropzone函数调用中指的是什么,但您可以尝试success: function (file, response) { /* do stuff */ }.bind( this ),
标签: javascript php jquery dropzone