您好,欢迎来到爱玩科技网。
搜索
您的当前位置:首页JS如何获取input中file的值并显示在页面

JS如何获取input中file的值并显示在页面

来源:爱玩科技网


本文主要为大家分享一篇JS获取input[file]的值并显示在页面的实现方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

实例如下所示:

$(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 = '<p class="photo-box"><img src="' + objUrl + '" alt=""><p class="photo-btn"><p>删除</p></p></p>';
 $(this).parent().parent().append(html);
})

Copyright © 2019- aiwanbo.com 版权所有 赣ICP备2024042808号-3

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务