您好,登錄后才能下訂單哦!
HTML中選擇圖片并直接預覽怎么弄?這個問題可能是我們?nèi)粘W習或工作經(jīng)常見到的。希望通過這個問題能讓你收獲頗深。下面是小編給大家?guī)淼膮⒖純?nèi)容,讓我們一起來看看吧!
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>選擇圖片并預覽</title> <script type="text/javascript"> function getFileUrl(sourceId) { var url; if (navigator.userAgent.indexOf("MSIE")>=1) { // IE url = document.getElementById(sourceId).value; } else if(navigator.userAgent.indexOf("Firefox")>0) { // Firefox url = window.URL.createObjectURL(document.getElementById(sourceId).files.item(0)); } else if(navigator.userAgent.indexOf("Chrome")>0) { // Chrome url = window.URL.createObjectURL(document.getElementById(sourceId).files.item(0)); } return url; } function preImg(sourceId, targetId) { var url = getFileUrl(sourceId); var imgPre = document.getElementById(targetId); imgPre.src = url; } </script> </head> <body> <p> <br /> <br /> <a>上傳者:<input type="text" /></a> <br /> <br /> <form action=""> <input type="file" name="imgOne" id="imgOne" onchange="preImg(this.id,'photo');" /> <br /> <br /> <img id="photo" src="" width="300px" height="300px" style="display: block;" /> </form> </p> </body> </html>
感謝各位的閱讀!看完上述內(nèi)容,你們對HTML中選擇圖片并直接預覽怎么弄大概了解了嗎?希望文章內(nèi)容對大家有所幫助。如果想了解更多相關文章內(nèi)容,歡迎關注億速云行業(yè)資訊頻道。
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。