2017-05-28 91 views
0

我想幫助jquery validate插件。我用它來檢查加載文件的擴展名。當擴展名不好時,它會提示更改文件,如果格式正確,則會將其考慮在內。 該插件在我的代碼中運行良好。問題是,當我點擊提交按鈕繼續,當它是正確的文件,按鈕不起作用,我不能去下一頁。然而,我的網頁之間有鏈接。你能幫我嗎 ?Jquery驗證文件擴展插件

+0

爲什麼你不能像這樣使用:。而不是簡單任務的驗證器。這將不允許用戶上傳文件比你指定 –

+0

嗨約翰。請閱讀:[如何創建最小,完整和可驗證示例](https://stackoverflow.com/help/mcve)並相應地更新您的問題。 –

回答

0
<!DOCTYPE html> 
<html dir="ltr" 
    lang="fr-FR" 
    xmlns:th="http://www.thymeleaf.org"> 
<head> 
<meta http-equiv="X-UA-Compatible" 
    content="IE=10"/> 
<meta http-equiv="Content-type" 
    content="text/html; charset=utf-8"/> 
<meta http-equiv="Expires" 
    content="0"/> 
<title th:text="${@environment.getProperty('spring.application.title') + ' - ' + serviceTitle} + ' - Livrer le DDX'"></title> 
<link id="favicon" 
    type="image/vnd.microsoft.icon" 
    rel="shortcut icon" 
    href="images/favicon.ico"/> 
<meta name="viewport" 
    content="width=device-width, initial-scale=1"/> 
<link rel="stylesheet" 
    href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js" type="text/javascript"></script>  
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" type="text/javascript"></script> 
<link id="mainCSS" type="text/css" rel="stylesheet" href="css/mainBS.css"/> 
<link id="workflowStageCSS" type="text/css" rel="stylesheet" href="css/workflow-stage.css"/> 
<link id="uploadDDXCSS" type="text/css" rel="stylesheet" href="css/uploadDDX.css"/> 
<script src="http://code.jquery.com/jquery-1.12.0.min.js"></script> 
<script src="http://cdn.jsdelivr.net/jquery.validation/1.14.0/jquery.validate.min.js"></script> 
<script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/additional-methods.min.js"></script> 
</head> 
<body>     <div class="articleBody"> 
         <form id="ddxForm" name="ddxForm" method="POST" enctype="multipart/form-data" th:action="${@environment.getProperty('server.context-path') + 'uploadDDX'}" > 
          <p class="ddx-block"> 
           <label id="ddx-file-label" 
           for="ddx-file" class="ddx-file-label" 
           >Fichier matlab(*):</label> <input id="ddx-file" 
           type="file" 
           name="ddx-file" 
           class="ddx-file" th:required="true"/>         
          </p><div><hr />       
           <input id="ddx-next" name="ddx-next" 
            type="submit" value="Continuer &gt;&gt;"/> <hr /></div> 
          </form></div>  
         </article> 
      </section> 
     </section> 
    </section> 
    <script> 
jQuery.validator.setDefaults({ 
    debug:true, 
    success:"valid" 
}); 
     $("#ddxForm").validate({ 
      rules:{ 
       "ddx-file":{ 
        required:true, 
        extension:"m" 
       } 
      } 
     }); 
</script> 
</body> 
</html> 
0

從爲調試選項的文檔:https://jqueryvalidation.org/validate/#debug

啓用調試模式。如果爲true,則表單未提交,並且控制檯上會顯示某些 錯誤(將檢查是否存在window.console 屬性)。嘗試啓用表單時,只需提交 即可停止提交。

嘗試在測試失敗案例後從setDefaults方法中除去'debug:true'。

+0

感謝Chris C的建議。我只需要從setDefaults方法中刪除'debug:true'。 – John