<form method="post">
<input type = "file" name ="file1">
<input type = "file" name ="file1">
<input type = "file" name ="file1">
</form>
我想检查输入字段是否为空。
Vanilla JS(您必须填充所有输入):
null
var inputs = document.getElementById("form").getElementsByTagName("input");
function check(){
for(let i = 0; i < inputs.length; i++){
if(inputs[i].value == ''){
console.log("input something!");
return false;
}
}
}
<form method="post" id="form" onsubmit="return check()">
<input type = "file" name ="file1">
<input type = "file" name ="file1">
<input type = "file" name ="file1">
<button>Submit</button>
</form>
您可以为此使用模糊功能。
null
$('input[type="file"]').blur(function(){
if(!$(this).val()){
//Put the code if not a file
} else{
//put the code here if file is present
}
});
<form method="post">
<input type = "file" name ="file1">
<input type = "file" name ="file1">
<input type = "file" name ="file1">
</form>