话不多说,直接上代码
<div id="head">
<img style="width: 80px;height: 80px" src="images/ckin.jpg" id="choice">
<input style="display: none" type="file" name="file" accept="image/*" value="0" id="changehead" onchange="read(this)">
</div>
//注意:由于在我的项目中,$符号与jQuery冲突了,所以这里我把$符号换成了jq
var jq = $.noConflict();
jq(function() {
// 点击修改头像
jq("#choice").click(function() {
// 点击input
jq("#changehead").click();
})
})
// 预览图片
function read(a) {
console.log(a.files);
var file = a.files[0];
//创建读取文件的对象
var reader = new FileReader();
//创建文件读取相关的变量
var imgFile;
//为文件读取成功设置事件
reader.onload = funct