[英]jQuery Image Preview From Text Box
我有Type="text"
這個輸入框,用於從file manager
選擇圖像。
HTML:
<input id="images" class="form-control" type="text" name="img">
從文件管理器中選擇圖像后,我有此輸出:
現在,我需要使用HTML和Jquery或Bootstrap Popover從此文本框和url創建圖像預覽。
我怎樣才能做到這一點?
不確定如何在輸入中輸入圖像,但是請嘗試此操作。
HTML:
<input id="images" class="form-control" type="text" name="img">
<div class="preview">
<img src="" class="preview-image" alt="">
</div>
<a href="http://cdn2.business2community.com/wp-content/uploads/2013/04/google-.jpg">Add Image</a>
CSS:
.preview-image { display: none; height: auto; width: 200px; }
JS:
$('.form-control').on('change', function(){
var inputVal = $(this).val();
$('.preview-image').attr('src', inputVal).fadeIn();
})
$('a').on('click', function(){
var href = $(this).attr('href');
$('.form-control').val(href).trigger('change');
return false;
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.