当前位置:编程学习 > asp >>

JQuery异部上传多个文件

这个例子需要用到JQuery和一个JQuery插件ajaxupload.js,不说太多。直接上代码:

前台:



<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script> 
   <script src="Scripts/ajaxupload.js" type="text/javascript"></script> 
 <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="Scripts/ajaxupload.js" type="text/javascript"></script>

<script type="text/javascript"> 
       $(document).ready(function () { 
           new AjaxUpload('#buttonUpload', { 
               action: 'Handler2.ashx', 
               data: { Folder: 'commodity', Count: $("#hidd_imgCount").val() }, 
               onSubmit: function (file, ext) { 
                   $("#loading").show(); 
                   if (!/^(jpg|bmp|png|gif)$/.test(ext)) { 
                       alert("只能上传格式为(bmp、jpg、png、gif)格式的图片!"); 
                       return false; 
                   } 
                   //判断上传图片的数量  
                   var imgCount = $("#hidd_imgCount").val(); 
                   if (parseInt(imgCount) >= 5) { 
                       alert("最多只能上传5张图片!"); 
                       $("#loading").hide(); 
                       return false; 
                   } 
                   this.disable(); 
               }, 
               onComplete: function (file, response) { 
 
                   $("#loading").hide(); 
                   this.enable(); 
                   var responseText = response.toString(); 
                   if (/MSIE 6.0/i.test(navigator.userAgent)) { 
                       responseText = getCookies(); 
                   } 
                   //显示1  
                   var reArray = responseText.split('|'); 
                   if (reArray[0] == "1") { 
                       alert("上传的文件不能大于4MB!"); 
                       return false; 
                   } 
                   else if (reArray[0] == null || reArray[0] == "") { 
                       alert("上传失败!"); 
                       return false; 
                   } 
                   else { 
                       var param = reArray[1]; 
                       if (reArray.length >= 3) { 
                           param += "|" + reArray[2]; 
                       } 
                       var divDocument = "<div id=\"" + reArray[1].substring(0, reArray[1].lastIndexOf('.') - 1) + "\" class=\"div_upfiles\">" + file + "     <a href=\"javascript:;\" onclick=\"delAttach('" + param.toString() + "','" + file + "');\">删除</a>" + "</div>"; 
                       $("#div_Result").append(divDocument); 
                   } 
                   //用于记录,上传的图片  
 
     &nbs

补充:Web开发 , ASP.Net ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,