如果我再次想要此警报消息,我必须刷新页面。
document.getElementById("images").addEventListener("change", function() {
var length = this.files.length;
if (length > 2) {
alert("you can not select more than 2 files")
}
});
<input class="control4" name="images[]" id="images" multiple="multiple" name="images" type="file" accept="image/jpg, image/jpeg,image/png" />
答案 0 :(得分:1)
对我有用,您第二次选择相同的文件吗?更改事件仅在值更改时触发,可以通过将输入值设置为空字符串来固定它。
document.getElementById("images").addEventListener("change", function() {
var length = this.files.length;
if (length > 2) {
this.value = "";
alert("you can not select more than 2 files");
}
});
<input class="control4" name="images[]" id="images" multiple="multiple" name="images" type="file" accept="image/jpg, image/jpeg,image/png" />