var input = document.getElementById ("J-btn-cont2");
var Img_area = document.getElementById ("Ul-box");
if (typeof (filereader) = = = ' undefined ') {
DialogBox (' Your browser does not support FileReader properties, please change to a major browser ');
Input.setattribute (' disabled ', ' disabled ');
} else {
$ (' #J-btn-cont2 '). On (' Change ', ' input[type=file] ', function () {
var length = $ (' #ul-box li '). length;
if (length >= 3) {
DialogBox (' Up to three images can be uploaded ');
return false;
}else{
var file = This.files[0];
ReadFile (file);
}
})
}
function ReadFile (file) {
Here we judge the type if it is not a picture to return to remove any file can be uploaded
if (!/image\/\w+/.test (File.type)) {
DialogBox ("Make sure the file is of image type");
return false;
}
var reader = new FileReader ();
Reader.readasdataurl (file);
Reader.onload = function (e) {
var carousel = This.result;
$.ajax ({
URL: '/mid/agency/multiupload ',
DataType: ' JSON ',
Type: ' POST ',
data:{' Carousel ': Carousel},
Success:function (res) {
if (Res.code = = 1) {
var _html = ' <li>\
\
<span class= "Delete-btn" ></span>\
<input type= "hidden" name= "carousel[" "value=" ' + Res.data + ' ">\
</li> ';
if ($ (img_area). Find (' Li '). Hasclass (' first ')) {
$ (img_area). HTML (");
$ (Img_area). Append (_html);
}else{
$ (Img_area). Append (_html);
}
}else{
DialogBox (RES.MSG);
}
}
})
}
}
Multi-image upload using var reader = new FileReader ();