css(图片删除图标样式):
<style type="text/css">
.isImg{position: relative; float: left; margin-left: 10px;}
.removeBtn{position: absolute; top: 0; right: 0; z-index: 11; border: 0px; border-radius: 50px; background: #A8DEFF; width: 20px; height: 20px; color: white;}
</style>
html:
<script type="text/javascript">
var imagepathArr=[];定义一个空数组
//删除图片js
function removeImage(obj,fileName){
$(obj).parent().remove();
imagepathArr.remove(fileName);
}
$(document).ready(function() {
$('#submitBtn').click(function() {
//数组转字符串
var imagepath=imagepathArr.toString();
$("#imagePath").val(imagepath);
if($("#saveForm").valid()) {
$("#saveForm").submit();
}
});
//多图上传
$("#files").omFileUpload({
action: "<%=uploadurl%>wxfileupload",
fileExt: "*.jpg;*.png;*.gif;*.jpeg;*.bmp",
fileDesc: "Image Files",
width:150,
sizeLimit: 1000 * 1024,
buttonText:"选择图片(500*250)",
onError: function(ID, fileObj, errorObj, event) {
if (errorObj.type == "File Size") {
alert("上传图片的大小不能超过1M");
}
},
onSelect: function(ID, fileObj, event) {
setTimeout(function() {
$("#files").omFileUpload({
actionData: {
uploadtype: "3"
}
});
$("#files").omFileUpload("upload");
},
10);
},
swf: "resources/wximport/js/om-fileupload.swf",
method: "GET",
onComplete: function(ID, fileObj, response, data, event) {
var jsonData = eval("(" + response + ")");
/*获取图片的URL,并加上删除按钮*/
var img="<div class='isImg'><img style='height: 100px;width: 100px;' src='"+jsonData.fileUrl+"'/> " +
"<button type='button' class='removeBtn' οnclick='removeImage(this,\""+jsonData.fileName+"\")'>x</button></div> ";
/*在图片后面追加一张图*/
$('#file_div').append(img);
imagepathArr.push(jsonData.fileName);
}
});
上传成功后在这里并排显示图片:
<tr>
<td width="20%" align="right" class="blue">众筹图片(多图):</td>
<td width="80%">
<input type="hidden" name="retUrl" value="<%=StringUtils.getParameter(request,"retUrl")%>" size=40/>
<div id="file_div" style="width: 800px;display: inline">
</div>
<div style="margin-top: 75px;padding-left: 8px">
<input type="hidden" name="imagePath" id="imagePath" value=""/>
<input id="files" type="button" multiple="multiple" />
</div>
</td>
</tr>
}