读存文件
作者:互联网
<input type="file" onchange="upload(this)" />
function upload(input) { //支持chrome IE10 if (window.FileReader) { var file = input.files[0]; filename = file.name.split(".")[0]; var reader = new FileReader(); reader.onload = function() { console.log(this.result); } reader.readAsText(file); } //支持IE 7 8 9 10 else if (typeof window.ActiveXObject != 'undefined'){ var xmlDoc; xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async = false; xmlDoc.load(input.value); console.log(xmlDoc.xml); } //支持FF else if (document.implementation && document.implementation.createDocument) { var xmlDoc; xmlDoc = document.implementation.createDocument("", "", null); xmlDoc.async = false; xmlDoc.load(input.value); console.log(xmlDoc.xml); } else { alert('error'); } } //////////////////////////////////////////////////////////// <input type="file" onchange="abc(this)" /> abc=(file)=>{ var reader = new FileReader(); reader.readAsText(file.files[0]) console.log(reader) }
标签:文件,console,log,读存,file,reader,var,xmlDoc 来源: https://www.cnblogs.com/buwngchuxin/p/12718844.html