码迷,mamicode.com
首页 > Web开发 > 详细

jquery文件上传html代码

时间:2017-07-22 18:26:16      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:org   gif   后缀   script   type   upload   dex   alert   3.2   

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script src="Scripts/jquery-1.3.2-vsdoc2.js" type="text/javascript"></script>
<script type="text/javascript">
function uploadImage() {
//判断是否有选择上传文件
var imgPath = $("#uploadFile").val();
if (imgPath == "") {
alert("请选择上传图片!");
return;
}
//判断上传文件的后缀名
var strExtension = imgPath.substr(imgPath.lastIndexOf(‘.‘) + 1);
if (strExtension != ‘jpg‘ && strExtension != ‘gif‘
&& strExtension != ‘png‘ && strExtension != ‘bmp‘) {
alert("请选择图片文件");
return;
}
$.ajax({
type: "POST",
url: "handler/UploadImageHandler.ashx",
data: { imgPath: $("#uploadFile").val() },
cache: false,
success: function(data) {
alert("上传成功");
$("#imgDiv").empty();
$("#imgDiv").html(data);
$("#imgDiv").show();
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("上传失败,请检查网络后重试");
}
});
}
</script>
</head>
<body>
<form enctype="multipart/form-data" method="post">
<input type="file" id="uploadFile" runat="server" />
<input type="button" id="btnUpload" value="确定" onclick="uploadImage()" />
<div id="imgDiv">
</div>
</form>
</body>
</html>

jquery文件上传html代码

标签:org   gif   后缀   script   type   upload   dex   alert   3.2   

原文地址:http://www.cnblogs.com/hopelooking/p/7221886.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!