Javascript 通过dropzone上传图像后,访问父div
我很困惑,我不知道如何访问父分区。让我总结一下 实际上我有多个dropzone,我使用类“.abc”初始化它 在每个dropzone上方都有一个输入,我将图像名称放在其中以便上传。这是我的密码Javascript 通过dropzone上传图像后,访问父div,javascript,php,jquery,dropzone,Javascript,Php,Jquery,Dropzone,我很困惑,我不知道如何访问父分区。让我总结一下 实际上我有多个dropzone,我使用类“.abc”初始化它 在每个dropzone上方都有一个输入,我将图像名称放在其中以便上传。这是我的密码 $('.kt_dropzone_1').dropzone({ url: base_url + 'product/uploadPic', // Set the url for your upload script location paramName: "file"
$('.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>
将文件放到此处或单击上载。
这只是一个演示
dropzone。所选文件为非
实际上上传了。
我尝试使用自定义属性传递输入id动态仍然不起作用
我不知道如何让当前的div对象访问父html或input或div,我可以建议您对此进行一些小的更改。将输入类型隐藏在 就在dropzone分区的上方 现在要参考正确的dropzone,请尝试以下更新的代码
$('.kt_dropzone_1').dropzone({
var this_dropzone = $(this);
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) {
this_dropzone.closest("div").find(".img-upload").attr('data-abe', 'value to be set');
this_dropzone.closest("div").find(".img-upload").val('you can set anyvalue here');
},
});
这应该是你想要的 我可以建议您对此进行一些小改动。将输入类型隐藏在 就在dropzone分区的上方 现在要参考正确的dropzone,请尝试以下更新的代码
$('.kt_dropzone_1').dropzone({
var this_dropzone = $(this);
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) {
this_dropzone.closest("div").find(".img-upload").attr('data-abe', 'value to be set');
this_dropzone.closest("div").find(".img-upload").val('you can set anyvalue here');
},
});
这应该是你想要的 在匿名回调函数
的范围内,此
不再引用父级-您可以尝试将该函数绑定到父级,以便访问此
@RamRaider。如何访问?不确定这是否有效,因为我不知道dropzone
函数调用中此引用了什么,但您可以尝试success:function(file,response){/*do stuff*/}.bind(this),
在匿名回调函数的范围内此
不再指父级-您可以尝试将函数绑定到父级,以便访问此
@RamRaider如何?不确定这是否有效,因为我不知道此
在dropzone
函数调用中指的是什么,但您可以尝试success:function(file,response){/*do stuff*/}.bind(this),
No这不起作用,显示错误!{var this_dropzone=$(this);}不,这不起作用,显示错误!{var this_dropzone=$(this);}