Home > Article > Web Front-end > How does JS get the value of input[file] and display it on the page? (Picture and text tutorial)
Below I will share with you a JS implementation method to obtain the value of input[file] and display it on the page. It has a good reference value and I hope it will be helpful to everyone.
The example is as follows:
$(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); })
The above is what I compiled for everyone, I hope it will be helpful to everyone in the future.
Related articles:
Example of vue combined with Echarts to achieve click highlighting effect
vue implements a label click highlighting Method
Vue-Highlight setting method of routing navigation menu bar
##
The above is the detailed content of How does JS get the value of input[file] and display it on the page? (Picture and text tutorial). For more information, please follow other related articles on the PHP Chinese website!