实例如下所示:
$(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); })
上面是我整理给大家的,希望今后会对大家有帮助。
相关文章:
以上就是JS如何获取input[file]的值并显示在页面的方法?(图文教程)的详细内容,更多请关注php中文网其它相关文章!
![php中文网最新课程二维码](/static/images/article_wechat2021.jpg?1111)
声明:本文原创发布php中文网,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论