2012-07-05 139 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