智慧大石
因为我没有生命,我想要这四个名望点,这样我就可以向那些真正擅长编码的人表达我的爱(请给出答案),我分享了我的改编。保罗·莫雷蒂密码。就用openFile(函数以文件内容作为第一个参数执行。).function dispFile(contents) { document.getElementById('contents').innerHTML=contents}function clickElem(elem) { // Thx user1601638 on Stack Overflow (6/6/2018 - https://stackoverflow.com/questions/13405129/javascript-create-and-save-file ) var eventMouse = document.createEvent("MouseEvents") eventMouse.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null) elem.dispatchEvent(eventMouse)}function openFile(func) { readFile = function(e) { var file = e.target.files[0]; if (!file) { return; } var reader = new FileReader(); reader.onload = function(e) { var contents = e.target.result; fileInput.func(contents) document.body.removeChild(fileInput) } reader.readAsText(file) } fileInput = document.createElement("input") fileInput.type='file' fileInput.style.display='none' fileInput.onchange=readFile fileInput.func=func document.body.appendChild(fileInput) clickElem(fileInput)}Click the button then choose a file to see its contents displayed below.<button onclick="openFile(dispFile)">Open a file</button><pre id="contents"></pre>