Created
September 26, 2017 10:47
-
-
Save RiceeeChang/58c4aefa3c0e054c538e1e907aa160b9 to your computer and use it in GitHub Desktop.
input select image preview with jquery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input type="file" name="cover"> | |
<img id="cover_preview" src=""> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 選圖片更新預覽圖 | |
$("input[name=cover]").on("change", function(){ | |
if (this.files && this.files[0]) { | |
var reader = new FileReader(); | |
reader.onload = function (e) { | |
$("#cover_preview").attr('src', e.target.result); | |
} | |
reader.readAsDataURL(this.files[0]); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment