swfupload多图上传限制图片张数
程序员文章站
2022-03-19 10:52:44
...
$.swfUpload({ id: 'spanButtonPlaceholder', post_params: { 'type': 'msg_flow', 'subType': 'h' }, isShowLoadImg: false, file_upload_limit: "6", upload_success_handler: uploadSuccess, file_queue_error_handler: uploadError, swfupload_loaded_handler : loaded, custom_settings: { upload_target: "divFileProgressContainer" } }); function loaded() { var $imageDiv = $("#pic_list"); var $imgList = $imageDiv.find("img"); var stats = SWFUpload.instances.SWFUpload_1.getStats(); stats.successful_uploads=$imgList.length; SWFUpload.instances.SWFUpload_1.setStats(stats); } function uploadError(file, code, message) { if (code == "-110") { alertmsg("文件大小超过" + "10M"); } else if (code == "-130") { alertmsg(file.name + "文件类型不支持上传,将不会被上传"); } else if (code == "-100") { alertmsg("图片上传数量超过" + 6 + "张,多余的不会上传"); } else { console.log(code); } } function uploadSuccess(file, serverData) { addImage(serverData); var img = ""; var $imageDiv = $("#pic_list"); var $imgList = $imageDiv.find("img"); for (var t = 0; t < $imgList.length; t++) { var $img = $($imgList[t]); img += $img.attr("src"); if (t != $imgList.length - 1) { img += ","; } } $('#imgList').val(img); var stats = SWFUpload.instances.SWFUpload_1.getStats(); stats.successful_uploads=$imgList.length; SWFUpload.instances.SWFUpload_1.setStats(stats); } function addImage(serverData) { var jsonData = $.parseJSON(serverData); var src = jsonData.url; if (jsonData.error == -1) { $("#qwErrAlert").qwPopup({content: "图片格式错误!"}); return; } var newElement = "<li style='float: left'><span class='del_img'><img onclick='bigPic(this);' class='upload_imgs' src='" + src + "'><a class='button'></a></span></li>"; $("#pic_list").append(newElement); $("a.button").bind("click", del); } var del = function () { $(this).parent().parent().remove(); var src = $(this).siblings('img').attr('src'); var img = ""; var $imageDiv = $("#pic_list"); var $imgList = $imageDiv.find("img"); for (var t = 0; t < $imgList.length; t++) { var $img = $($imgList[t]); img += $img.attr("src"); if (t != $imgList.length - 1) { img += ","; } } $('#imgList').val(img); var stats = SWFUpload.instances.SWFUpload_1.getStats(); stats.successful_uploads=$imgList.length; SWFUpload.instances.SWFUpload_1.setStats(stats); };
html
<tr id="mainImg"> <th><em>*</em>正面图片:</th> <td> <div style="width: 500px; height: auto; border: 1px solid #e1e1e1; font-size: 12px; padding: 10px;"> <span id="spanButtonPlaceholder"></span> <em id="emName9" style="display: none;">必须选择6张图片</em> <div id="divFileProgressContainer"></div> <div id="thumbnails"> <ul id="pic_list" style="margin: 5px;"></ul> <div style="clear: both;"></div> </div> </div> <input type="hidden" name="imgList" id="imgList" value=""/> </td> </tr>
上一篇: 读Objects源码
下一篇: springmvc执行过程