首页 > 技术文章 > 图片上传

kxkl123 2017-12-06 00:10 原文

摘要---保存

一.验证图片格式JS:

  

/** 提交照片表单 */
function uploadImg() {
var photo = $("#pathForm .uploadInput").val();
var ends = photo.split(".")[1];
if (ends!="png" && ends!="jpg" && ends!="jpeg") {
util.dialog.error("照片格式有误,请重新选择!");
return;
}
$("#pathForm")[0].submit();
}
/**
* 提交照片回调函数
* 处理回调后显示照片
* @param path
*/
function callback(path, photoId) {
if (path == null) {
util.dialog.error("图片上传失败,请重试!");
return;
} else if (path == "fileTooBig") {
util.dialog.error("图片大小超过1MB,请重试!");
return;
}
var html = '<li class="fl">';
html += '<input type="hidden" class="photoId" value="'+photoId+'" />';
html += '<div class="imgDelDiv"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></div>';
html += '<div class="doorImg"><img src="'+r.host+path+'" /></div></li>';
$(".room_imgUl").append(html);
// 绑定点击放大
$(".doorImg img").last().bind("click", function(){
showBigImg($(this));
});
// 绑定删除图片
$(".imgDelDiv").last().bind("click", function(){
delImg($(this));
});
}
/** 图片点击放大 **/
function showBigImg($this) {
var imgUrl = $this.attr("src");
art.dialog({
content : '<img style="max-height:600px;" src="'+imgUrl+'" />',
lock : true
});
}
/** 删除图片 **/
function delImg($this) {
var delPhotoId = $this.parent().find(".photoId").val();
if (delPhotoId == null || delPhotoId == "") {
util.dialog.error("删除照片失败,请刷新后重试");
}
util.ajax(r.host+"house/house/editFsRoom/delImg", {
fsRoomId: $("#fsRoomId").val(),
delPhotoId: delPhotoId
}, function(msg){
$this.parent().remove();
});
}

推荐阅读