實例如下所示:
$(document).on('change', '.photo-box .file', function () { //alert($(this).val()); function getObjectURL(file) { var url = null; if (window.createObjectURL != undefined) { // basic url = window.createObjectURL(file); } else if (window.URL != undefined) { // mozilla(firefox) url = window.URL.createObjectURL(file); } else if (window.webkitURL != undefined) { // webkit or chrome url = window.webkitURL.createObjectURL(file); } return url; } var objUrl = getObjectURL(this.files[0]); console.log("objUrl = " + objUrl); var html = '<div class="photo-box"><img src="' + objUrl + '" $(this).parent().parent().append(html);})以上這篇JS獲取input[file]的值并顯示在頁面的實現(xiàn)方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持VeVb武林網(wǎng)。
新聞熱點
疑難解答