0

这是我的 JS 代码:

<script type="text/javascript">
  $(document).ready(function () {
      $("#form").validate({
          rules: {
              sub: "required",
              msg: "required"
          }
      });
  }); 
</script> 

这是脚本导入:

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>     
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></script>

这是我的 MVC 表单:

<% using (Html.BeginForm("RepR", "Agence", FormMethod.Post, new { @class = "search_form", @id= "form"})) { %>
  <%: Html.ValidationSummary(true) %>
  <%: Html.Hidden("to", Model.mailc) %>
  <p>
    Sujet : <br />
    <%: Html.TextBox("sub")%> 
    <%: Html.ValidationMessage("sub","Suijet est obligatoire") %>
    <br />
    Message : <br />
    <%: Html.TextArea("msg", new { @cols = "50", @rows = "5" })%> 
  </p>
  <input type="submit" value="Envoyer" class="button"/>

这是 Html 代码源:

  <script src="../../Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
  <script src="../../Scripts/jquery.ui.datepicker.js" type="text/javascript"></script>
  <script src="../../Scripts/jquery.ui.core.min.js" type="text/javascript"></script>
  <script src="../../Scripts/jquery.ui.widget.js" type="text/javascript"></script>
  <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> 
  <script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></script>
</head>
    <body>
        //html code
        <script type="text/javascript">
            $(document).ready(function () {
                $("form").validate({
                    rules: {
                      sub: "required",
                      msg: "required"
                    }
                });
            }); 
        </script> 

    //html code
    <form action="/Agence/RepR/9" class="search_form" method="post">
        <input id="to" name="to" type="hidden" value="kaouach.ahmed@gmail.com" />
        <p>
            Sujet : <br />
            <input id="sub" name="sub" type="text" value="" /> 
            <span class="field-validation-valid" data-valmsg-for="sub" data-valmsg-replace="false">Suijet est obligatoire</span>
            <br />
             Message : <br />
            <textarea cols="50" id="msg" name="msg" rows="5"></textarea> 
        </p>
        <input type="submit" value="Envoyer" class="button"/>
    </form>

谁能告诉我为什么它不起作用,即不进行验证?

4

1 回答 1

0

您的验证插件链接返回 404 错误:http ://bugs.jquery.com/view/trunk/plugins/validate/jquery.validate.js

您可以将其用于开发:http: //jzaefferer.github.com/jquery-validation/jquery.validate.js

于 2012-04-30T22:21:45.550 回答