0
我GOOGLE了它,發現我可以聽輸入類型=「文件」onchange事件。但是這隻適用於沒有多個屬性的輸入。有誰知道如何聆聽「文件選擇」事件並在用戶選擇文件後觸發功能?如何檢測(在js中)是否在HTML5多輸入中選擇文件?
我GOOGLE了它,發現我可以聽輸入類型=「文件」onchange事件。但是這隻適用於沒有多個屬性的輸入。有誰知道如何聆聽「文件選擇」事件並在用戶選擇文件後觸發功能?如何檢測(在js中)是否在HTML5多輸入中選擇文件?
<input type="file" multiple name="files" />
和jQuery中:
$("input[type='file']").on("change", function(){
var files = $(this).prop("files"); // you'll get selected file(s)
console.log(files); // here will display files as objects with their properties. Check with Chrome console what properties are.
});
如果files
是不確定的,則瀏覽器必須支持HTML5。