基本上我有一個表格,裏面有一個圖像文件輸入框,現在我需要顯示從文件輸入中選擇的圖片,並在沒有表格提交。如何在提交表單之前加載圖像
我發現了一個教程,說:
<!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>
但這不顯示在我的圖像框中選擇圖像。