js验证上传的文件是否为JPEG,PNG,JPG,GIF格式
来源:互联网 发布:原生js获取json文件 编辑:程序博客网 时间:2024/04/30 08:24
function checkPhoto(){ var type=""; if(document.getElementById("newphoto").value!=''){ type=document.getElementById("newphoto").value.match(/^(.*)(\.)(.{1,8})$/)[3]; type=type.toUpperCase(); } if(type!="JPEG" && type!="PNG" && type!="JPG" && type!="GIF"){ alert("上传图片类型错误"); return false; } }
form表单,验证文件类型,文本是否为空,文本长度验证
js
<script type="text/javascript"> //进入下一步 function subForm() {form1.submit(); //form1为form的id } //表单验证 $(function(){$("#addsubmit").click(function(){//表单校验if(validate()){$("#form1").submit();}});//进入文本框 隐藏错误提示框$("input").click(function(){$("#errorId").hide();});});//进行js校验 表单function validate(){var title =$.trim( $("#title").val());var content = $.trim($("#content").val());if(title == ""){//显示错误提示框$("#title").show();alert("标题不能为空")$("#title").html("标题不能为空");return false;}if(content == ""){//显示错误提示框$("#content").show();alert("内容不能为空")return false;}if(title.length>50){//显示错误提示框$("#title").show();alert("标题字数不能超过50字")$("#title").html("标题字数不能超过50字");return false;} var type=""; if(document.getElementById("pic").value!=''){ type=document.getElementById("pic").value.match(/^(.*)(\.)(.{1,8})$/)[3]; type=type.toUpperCase(); } if(type!="JPEG" && type!="PNG" && type!="JPG" && type!="GIF"){ alert("上传图片类型错误,只能上传JPEG,png,jpg类型图片"); return false; } return true;} </script>
form
<form id="form1" action="${pageContext.request.contextPath}/information/updateInformation.shtml" method="post" enctype="multipart/form-data"> <input name="loginId" type="hidden" value="${userInfo.loginId}"/> <input name="schschoolId" type="hidden" value="${userInfo.schschoolId}" /> <input name="id" type="hidden" value="${information.id}" /> <span class="left">文章标题:</span> <input id="title" type="text" class="text left w350 mr20" name="title" value="${information.title }" /> <span class="left">是否仅限本校学生查看:</span> <div class="dropdown text w80 mr20"> <select id="select_k1" class="shadow" name="display" > <option value="1" <c:if test="${information.display==1 }"> selected</c:if> >是</option><option value="0" <c:if test="${information.display==0 }"> selected</c:if> >否</option> </select> <!-- 登陆id --> </div> <span class="left">类型:</span> <div class="dropdown text w80 mr20"> <select name="type" id="select_k1" class="shadow"><option value="1" <c:if test="${information.type==1 }"> selected</c:if> >高校专版</option><option value="2" <c:if test="${information.type==2 }"> selected</c:if>>发现</option> </select> </div> <span class="left">是否为轮播图:</span> <div class="dropdown text w80 mr20"> <select name="isFigure" id="select_k1" class="shadow"><option value="0" <c:if test="${information.isFigure==0 }"> selected</c:if>>否</option><option value="1"<c:if test="${information.isFigure==1 }"> selected</c:if>>是</option> </select> </div> <c:if test="${!empty information.coverImgUrl }"> <img src="${ information.coverImgUrl }" /> </c:if> <span class="left" style="width:80px; height:15px;"></span> <span class="left" >封面图:</span> <input id="pic" type="file" class="text left w200 mr10" name="pic" value="${ information.coverImgUrl }" /> <textarea id="content" name="content" style="width:98%; height:185px;"> ${content } </textarea> <div class="text-box pr30"><div class="btn-box"> <!--part--> <div class="part tr"> <!-- <a title="发布" class="blue-btn btn-big mr10" onclick="subForm();">修改</a>--> <a title="发布" id="addsubmit" href="javascript:;" class="blue-btn btn-big mr10">发布</a> <a title="取消" class="btn gray-btn btn-big mr10" href="informationList.shtml">取消</a> </div> <!--part end--> </div> </div> </form>
0 0
- js验证上传的文件是否为JPEG,PNG,JPG,GIF格式
- js验证上传的文件是否为JPEG,PNG,JPG,GIF格式
- java web - 限制文件的上传类型为图片类型(.gif,.png,.jpg,.jpeg)
- 解决eWebEditor上传图片提示:请选择一个有效的文件,支持的格式有(GIF|JPG|JPEG|BMP|PNG)!
- 加载JPG / JPEG / GIF / PNG 格式的图片
- js 实现检查上传文件的格式,文件为.jpg或.png为正确格式,其它为错误。
- 判断上传照片的类型是否是"jpg","jpeg","png"
- 判断文件是否为gif/jepg/png等格式
- 常见图片格式jpg、jpeg、png、gif等之间的区别
- [Ext JS 4] 实战之将chart导出为png, jpg 格式的文件
- JAVA读取EMF文件并转化为PNG,JPG,GIF格式
- 常见图片格式jpg、jpeg、png、gif…
- C#使用GDAL将tif图像转换为jpg、bmp、png和gif格式的图像
- (AutoIt 实例)图片批量重命名小工具,支持jpg、jpeg、png、gif格式
- png,jpeg,gif和eps格式的互转问题
- 介绍图片的三种格式:GIF、JPEG、PNG
- png,bmp,jpg,gif格式图像的区别
- jpg,gif和png三种格式图片的说明
- c++ STL 数据结构底层结构
- 正则表达式学习及应用
- Finished with Non Zero Exit Value 3
- 如何使用红杏的公益代理
- 跟我一起学OC系列-布尔类型
- js验证上传的文件是否为JPEG,PNG,JPG,GIF格式
- 对于无线传感网的初步认识
- AutoCAD套合(叠加)卫星影像和矢量路网数据-CAD配准
- Wildcard Matching_Leetcode_#44
- SELinux深入理解
- Jenkins+Maven+SVN+Sonar持续集成(一)Centos6.5上Jenkins安装
- Open Win32 App in C#, with extern keyword
- java处理错误
- MapReduce工作原理图文详解