加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ajaxFileUpload图片上传、限制后缀和张数 带参数

发布时间:2020-12-16 00:54:07 所属栏目:百科 来源:网络整理
导读:ajaxFileUpload图片上传、限制后缀和张数 带参数 HTML: input type="file" name="img" id="fileToUpload" style="width:180px;" onchange="ajaxFileUpload(this);" /span class="info"(最多可上传三张图片,图片宽高比例3:2,大小不超过300KB)/span/td s

ajaxFileUpload图片上传、限制后缀和张数 带参数


HTML: <input type="file" name="img" id="fileToUpload" style="width:180px;" onchange="ajaxFileUpload(this);" /><span class="info">(最多可上传三张图片,图片宽高比例3:2,大小不超过300KB)</span></td>


<script language="javascript" src="../assets/static/js/ajaxfileupload.js"></script>
js:


var i = 0; function ajaxFileUpload(fileObj) { if (i < 3) { var allowExtention = ".jpg,.bmp,.gif,.png"; //允许上传文件的后缀名document.getElementById("hfAllowPicSuffix").value; var extention = fileObj.value.substring(fileObj.value.lastIndexOf(".") + 1).toLowerCase(); var browserVersion = window.navigator.userAgent.toUpperCase(); if (allowExtention.indexOf(extention) > -1) { $.ajaxFileUpload({ url: 'ajax_imgupload.jsp',secureuri: false,fileElementId: 'fileToUpload',data: { "types": "1" },dataType: 'json',success: function(data,status) { if (typeof(data) != 'undefined') { $.each(data,function(k,v) { $(".imagelist").find("li").eq(i).find("img").attr("src",v.url).attr("id",v.id).removeAttr("title"); i++; }); } },}); } else { alert("仅支持" + allowExtention + "为后缀名的文件!"); fileObj.value = ""; //清空选中文件 if (browserVersion.indexOf("MSIE") > -1) { fileObj.select(); document.selection.clear(); } fileObj.outerHTML = fileObj.outerHTML; } } else { alert("最多可上传三张图片"); } }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读