如果輸入值只有輸入,那麼用戶應該能夠上傳文件。但是一旦我點擊按鈕窗口上傳文件彈出。我不希望它除非用戶輸入下面所述的輸入文件中的值,否則彈出。 這些輸入:阻止使用javascript彈出的上傳窗口
<input type="text" id="id" placeholder="Enter Audit ID" autocomplete="off">
<input type="text" id="email_id_upload" placeholder="Enter Email_id " autocomplete="off">
這是上傳:
<form>
<input type="file" name="file" id="file"><br>
<input type="button" name="submit_file" value="Submit">
</form>
這是JS來檢查用戶是否有輸入的所有值:
$('#file').click(function(){
var email_id_upload= $('#email_id_upload').val();
var id = $('#id').val();
if(email_id_upload.length !==0 && id.lenght !==0)
{
//allow upload window to pop up
}
else
{
if(email_id_upload.length ===0 && id.length ===0)
{$('#message_content2_1').html("<span style='color:red'>Please fill email id and audit id</span>");}
else{
if(email_id_upload.length ===0)
{$('#message_content2_1').html("<span style='color:red'>Please fill email id</span>");}
if(id.length ===0)
{$('#message_content2_1').html("<span style='color:red'>Please fill email id and audit id</span>");}
}
}
});
添加'返回false'在點擊功能,無論你想阻止點擊做任何事情 –