前端图片回显

<form>
	<label>书名</label><input type="text" id="name" name="name" /> <br />
	<label>作者</label><input type="text" id="author" name="author" /> <br />
	<label>出版社</label><input type="text" id="press" name="press" /> <br />
	<label>出版时间</label><input type="date" id="pressDate" name="pressDate" /> <br /> 
	<label>图书描述</label><input type="text" id="describe" name="describe" /> <br /> 
		
	<!--选择文件后触发函数-->
	<input type="file" onchange="change(this)" id="bookImg" name="bookImg"> <br /> 
		
	<img id="upLoadImg" /> <br /> <input type="submit" id="submitButton" />
</form>
function change(img) {
			var file = img.files[0];
			//获取一个指向该元素的地址
			var path = window.URL.createObjectURL(file);
			console.log(path);
			$("#upLoadImg").attr('src', path);
		}
//如果不使用this,也可以使用jq直接获取控件
$("bookImg").get(0).files[0]
//js获取
var inputTag = document.getElementById("bookImg");
var img = inputTag.files[0];

猜你喜欢

转载自blog.csdn.net/candy_27/article/details/83961812