提问者:小点点

如何在python中检查输入类型文件是否为空


<form method="post">
<input type = "file" name ="file1">
<input type = "file" name ="file1">
<input type = "file" name ="file1">    
</form>   

我想检查输入字段是否为空。


共2个答案

匿名用户

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>