jqueryを使用してHTMLフォームからパスを選択した後にイメージを表示するサンプルコードがあります。コードはここにあります:htmlフォームからパスを選択した後に画像を表示
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="description" content="">
<meta name="author" content="">
<title>Image Test</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imgInp").change(function(){
readURL(this);
});
</script>
</head>
<body>
<form id="form12" runat="server">
<input type='file' id="imgInp" />
<img id="blah" src="#" alt="your image" />
</form>
</body>
</html>
しかし、画像を選択した後、パスが表示され、画像が表示されません。どこに問題がありますか?
最後に 'body'の中に' script'タグを追加して、一度試してみてください。 –