我喜欢输入文件:
<input type="text" id="txtPath" placeholder="No file selected" />
<input id="btnBrowse" type="button" value="Browse..." onclick="document.getElementById('file').click();" />
<input type="file" id="loadFile" style="display:none;" id="file" name="file" />
我想提醒所选路径,我尝试过:
document.getElementById("loadFile").addEventListener("change", function(event) {
let output = document.getElementById("txtPath");
let files = event.target.files;
alert(files);
},false);
但这不起作用,错误:
无法读取null的属性“点击”
答案 0 :(得分:1)
您有重复的id
供输入:
id =“ loadFile” style =“ display:none;” id =“ file”
<input type="text" id="txtPath" placeholder="No file selected" />
<input id="btnBrowse" type="button" value="Browse..." onclick="document.getElementById('file').click();" />
<input type="file" style="display:none;" id="file" name="file" />
世界示例jsfiddle