jQuery("#image-div").on('dragleave',function(e){
document.getElementById("image-div").style.borderColor = "#E6E6E6";
return false;
});
jQuery("#image-div").on('dragover',function(e){
document.getElementById("image-div").style.borderColor = "#9B9999";
return false;
});
jQuery("#image-div").on('drop',function(e){
event.preventDefault && event.preventDefault();
var files = event.dataTransfer.files[0];
if (files.type.match("image.*"))
{
var fileReader = new FileReader();
fileReader.onload = function (event)
{
uploadImage(event.target.result);
}
fileReader.readAsDataURL(files);
}
return false;
});
Don't know what is wrong in my code. It is working for Chrome and IE. When Ii drop an image I need to drop it in a div but instead, it opens in a tab.
Because you defined event as e, but using window.event.
jQuery("#image-div").on('drop',function(e){ <-- e
event.preventDefault && event.preventDefault(); <-event
一件事只是看您的代码,我认为您需要使用e代替事件,除非您引用的事件范围超出了我无法看到的范围。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.