2012-07-05 144 views
2

Jquery无法在Internet Explorer上工作。然而它运行在其他网页浏览器上。 这是我写的代码是在Internet Explorer上使用jquery问题

<html> 
<head> 
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script> 
    <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script> 
    <script type="text/javascript"> 
    $(document).ready(function(){ 
     $("#myform").validate({ 
      debug: false, 
      rules: { 
       name: "required", 
       email: { 
        required: true, 
        email: true 
       } 
      }, 
      messages: { 
       name: "Please let us know who you are.", 
       email: "A valid email will help us get in touch with you.", 
      }, 
      submitHandler: function(form) 
      { 
       $.post('process.php', $("#myform").serialize(), function(data) 
       { 
        $('#results').html(data); 
       }); 
      } 
     }); 
    }); 
    </script> 

</head> 
<body> 
<form name="myform" id="myform" action="" method="POST"> 
    <label for="name" id="name_label">Name</label> 
    <input type="text" name="name" id="name" size="30" value=""/> 
    <br> 
    <label for="email" id="email_label">Email</label> 
    <input type="text" name="email" id="email" size="30" value=""/> 
    <br> 
    <input type="submit" name="submit" value="Submit"> 
</form> 
<div id="results"><div> 
</body> 
</html> 

process.php

<?php 
    print "Form submitted successfully: <br>Your name is <b>".$_POST['name']."</b> and your email is <b>".$_POST['email']."</b><br>"; 
?> 

如何运行的Internet Explorer。任何帮助,这个代码在此

+1

您是否收到JavaScript控制台的错误消息?你使用的是什么版本的IE?我们是开发者,也不是魔术师:) – Devraj 2012-07-05 09:45:31

+0

没有错误。当我点击提交按钮时,我再次获得相同的页面询问姓名和电子邮件 – jat 2012-07-05 09:47:12

回答

2

删除 '' 这行后

email: "A valid email will help us get in touch with you.", 

应该

email: "A valid email will help us get in touch with you." 

在您的信息块就是这个样子

messages: { 
      name: "Please let us know who you are.", 
      email: "A valid email will help us get in touch with you.", // <<<< HERE REMOVE IT     
     }, 

您需要删除最后一行中的','(逗号),不需要它。

+0

对不起,我做了没有得到你? – jat 2012-07-05 10:02:18

+0

已经编辑我的anwser再次检查, – 2012-07-05 10:04:03

+0

谢谢 。它工作得很好:) – jat 2012-07-05 10:08:46

0

非常感谢您应该添加return falsesubmitHandler

或者您可以将您的提交输入转换为不使用<button>Submit</button>提交表单的按钮。

+0

我加了返回false,但它没有区别:( – jat 2012-07-05 09:51:41

+0

尝试使用按钮标记'

+0

这两者都没有做这个工作!! – jat 2012-07-05 10:03:21

0

试试下面的代码: -

<script type="text/javascript"> 
    $(document).ready(function(){ 
    $("#myform").validate({ 
     debug: false, 
     rules: { 
      name: "required", 
      email: { 
       required: true, 
       email: true 
      } 
     }, 
     messages: { 
      name: "Please let us know who you are.", 
      email: "A valid email will help us get in touch with you.", 
     }, 
     submitHandler: function(form) 
     { 
      $.post('process.php', $("#myform").serialize(), function(data) 
      { 
       $('#results').html(data); 
      }); 
      return false; 
     } 
    }); 
}); 
</script> 
+0

否:(即使点击提交按钮 – jat 2012-07-05 09:55:27

0

我想在我结束时执行代码。请在顶部添加文档类型。我也是这样使用的,它在早期不工作的情况下工作。

<!DOCTYPE html> 

感谢

+0

总是使用html5 doctype并且从不xhtml doctype! – Christoph 2012-07-05 09:53:51

+0

哪个版本的互联网资源管理器是否使用我的朋友?它仍然不适用于我:( – jat 2012-07-05 09:58:26

+0

我正在使用iE8。你在页面的顶部使用了什么.BTW评论你的代码并尝试逐步调试它。 – 2012-07-05 10:04:13