基本上我有一个表格,里面有一个图像文件输入框,现在我需要显示从文件输入中选择的图片,并在没有表格提交。如何在提交表单之前加载图像
我发现了一个教程,说:
<!DOCTYPE html>
<html>
<head>
<script>
var reader = new FileReader();
reader.onload = function (e) {
$('#blah').attr('src', e.target.result);
}
function readURL(input) {
if (input.files && input.files[0]) {
reader.readAsDataURL(input.files[0]);
}
}
$("#imgInp").change(function(){
readURL(this);
alert(input.val());
});
</script>
</head>
<body>
<form id="form1" runat="server">
<input type='file' id="imgInp" />
<img id="blah" src="#" alt="your image" />
</form>
</body>
</html>
但这不显示在我的图像框中选择图像。