3
我有一些HTML元素:如何在Jquery中預覽圖像?
<img id="preview_image" alt="" src="" width="100px" height="120px">
<br>
<input type="file" name="user_image" id="user_image" onchange="preview(this);">
這裏的JS:
function preview(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#preview_image')
.attr('src', e.target.result)
.width(100)
.height(120);
};
reader.readAsDataURL(input.files[0]);
}
}
當我選擇圖像時,它會立即預覽。
現在我想要的是:首先,選擇一個圖像(但不是現在預覽),然後點擊超鏈接,圖像將被顯示。超鏈接是這樣的:
<a href="javascript:void(0)" onclick="preview2()">Click to preview</a>
preview2 = function(){
//what should I do here (using Jquery)
}
非常感謝!