<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
<meta name="description" content="">
<meta name="author" content="">
<title>票据清单录入</title>
<!-- Custom styles for this template -->
<script src="jquery.min.js" type="text/javascript"></script>
<script src="ajaxfileupload.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
//头像预览
$("#headPic").click(function () {
$("#upload").click(); //隐藏了input:file样式后,点击头像就可以本地上传
$("#upload").on("change",function(){
var objUrl = getObjectURL(this.files[0]) ; //获取图片的路径,该路径不是图片在本地的路径
if (objUrl) {
$("#headPic").attr("src", objUrl) ; //将图片路径存入src中,显示出图片
}
});
});
//图片上传
$("#submit_btn").click(function () {
var imgurl = document.getElementById("upload").value;
$.ajaxFileUpload({
url:" http://114.55.4.234/hgl/webFileUpload",
secureuri:false,
type:"get",
fileElementId: "upload", //文件上传域的ID,这里是input的ID,而不是img的
dataType: 'text', //返回值类型 一般设置为json
contentType: "application/x-www-form-urlencoded; charset=utf-8",
success: function (e) {
console.log(e.response);
//alert(data.url);
},
error:function(data,status,e){
alert(e);
}
});
});
});
//建立一個可存取到該file的url
function getObjectURL(file) {
var url = null ;
if (window.createObjectURL!=undefined) { // basic
url = window.createObjectURL(file) ;
} else if (window.URL!=undefined) { // mozilla(firefox)
url = window.URL.createObjectURL(file) ;
} else if (window.webkitURL!=undefined) { // webkit or chrome
url = window.webkitURL.createObjectURL(file) ;
}
return url ;
}
</script>
</head>
<body style="padding-top: 10px;">
<div class="container-fluid peian dw_luru">
<div >
<label >点击图片即可修改</label><br>
<img id="headPic" src="image/a.png" width="150px" height="150px" style="padding: 5px">
<input id="upload" name="file" accept="image/*" type="file" style="display: none"/>
<button id="submit_btn" type="submit">确定修改</button>
</div>
</div>
</body>
</html>