JQuery验证无法在IE 11中运行

时间:2014-05-05 13:06:24

标签: javascript php jquery validation

我正在尝试使用PHP使用jquery验证来验证表单。我已经使用谷歌完成了所有这些......我是网络开发的新手。表格在FF中工作得非常好,但脚本不是在IE 11中工作...我很感谢...感谢...代码如下:

<script src="js/jquery-1.9.0.js"></script>

  <script src="js/jquery.validate.min.js"></script>

  <!-- jQuery Form Validation code -->
  <script>

  // When the browser is ready...


 $function() {

    // Setup form validation on the #register-form element
    $("#register-form").validate({

        // Specify the validation rules
        rules: {
            topic: "required",
            detail: "required",
            name: "required",
            email: {
                required: true,
                email: true
            },

        },

        // Specify the validation error messages
        messages: {
            topic: "Enter the subject for your suggestion",
            detial: "Please enter your suggestion",
            name: "Please enter your name. It will be kept hidden",
            email: "Please enter a valid email address",
           /* username: "Please enter a valid username",
            password: {
                required: "Please provide a password",
                minlength: "Your password must be at least 5 characters long"
            }*/
        },

        submitHandler: function(form) {
            form.submit();
        }
    });

  });

  </script>



<table align="center" width="800px" border="1" class="table_css">
  <?php echo $output; ?>
  <!--  The form that will be parsed by jQuery before submit  -->
  <tr><td  >Submit Your Suggestion</td></tr>
  <tr><td>
  <form action="add_topic.php" method="post" id="register-form"  name="register-form" novalidate>

    <div class="label">Subject</div><input type="text" id="topic" name="topic" value="<?php echo $topic; ?>" size="50"/><br />
    <div class="label">Suggestion</div>
    <textarea name="detail" cols="60"  id="detail" rows="15" value="<?php echo $detail; ?>"></textarea><br />

    <div class="label">Name</div><input type="text" id="name" name="name" value="<?php echo $name; ?>" size="30" /><br/>
    <div class="label">Email</div><input type="text" id="email" name="email" value="<?php echo $email; ?>" size="30"/><br /><div style="margin-left:200px;"><input type="submit" name="submit" value="Submit" /><input type="reset" name="Submit2" value="Reset" /></div>
    </form>
  </td>
  </tr>
  </table>

5 个答案:

答案 0 :(得分:3)

我有类似的问题。我添加了以下代码来设置Internet Explorer的浏览器兼容性以使其运行。在<head>代码中添加以下代码。

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

它使脚本在IE11中工作。

答案 1 :(得分:1)

您只需使用关键字&#34; required&#34; HTML5。

<input type="text" required>

DEMO HERE

答案 2 :(得分:0)

更改提交按钮的名称

<input type="submit" name="submit" value="Submit" />

除了提交之外的其他内容。

<input type="submit" name="btnSubmit" value="Submit" />

答案 3 :(得分:0)

从另一个主题看,IE看起来并不能很好地处理过多的逗号。尝试删除消息和规则对象中email属性后的逗号。

答案 4 :(得分:0)

https://github.com/jquery-validation/jquery-validation/issues/2225 1.18.0版本中的问题

一个安全的解决方案是安装1.17.0版-> npm install jquery-validation@1.17.0并检查插件是否确实是1.17.0版