我无法使用jQuery为以下Document验证ASP输入

时间:2016-12-25 04:30:44

标签: javascript jquery asp.net twitter-bootstrap validation

head runat="server">
    <title></title>

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
    <script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.16.0/jquery.validate.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    <script type="text/javascript">
         $document.ready(function(){
    $("#Form1").validate({
        rules:{
          txtFname:{
                required:true,
                rangelength:[3,20],
            }
        },
        messages: {
            txtFname: "First Name Is Required",
        }
    })
            })//ready function close
        </script>
</head>
<body>
    <form id="Form1" runat="server" clientidmode="static">
        <asp:TextBox ID="txtFname" CssClass="form-control" runat="server"></asp:TextBox>
        <asp:Button CssClass="btn btn-primary" id="btnSubmit" runat="server" Text="Submit"/>
    </form>
</body>

我正在尝试验证模式中第1行表单中的txtFname字段,但我无法...我似乎无法弄清楚原因。有人可以帮忙吗? 我正在使用bootstrap v3

1 个答案:

答案 0 :(得分:1)

看起来像语法问题(括号,一些额外冒号和缺少分号......等)

尝试以下方法应该有效:

<script type="text/javascript">
     $(document).ready(function() {
         $("#Form1")
             .validate({
                 rules: {
                     txtFname: {
                         required: true,
                         rangelength: [3, 20]
                     }
                 },
                 messages: {
                     txtFname: "First Name Is Required"
                 }
             });
     })//ready function close
    </script>