Jquery验证插件的文件扩展名

时间:2017-05-28 16:06:10

标签: jquery

我想帮助jquery validate插件。我用它来检查加载文件的扩展名。当扩展名不好时,它会提示更改文件,当它是正确的格式时,会将其考虑在内。 该插件在我的代码中运行良好。问题是当我点击提交按钮继续它是正确的文件时,按钮不起作用,我不能转到下一页。然而,我的网页之间有链接。你能帮帮我吗?

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

来自调试选项的文档:https://jqueryvalidation.org/validate/#debug

  

启用调试模式。如果为true,则表单未提交且确定   错误显示在控制台上(将检查window.console   财产存在)。尝试在刚刚提交表单时启用   验证停止提交。

尝试删除&#39; debug:true&#39;在测试失败案例后,从setDefaults方法开始。