37

我試圖在我的網站上使用表格上的jQuery Validation插件。該表單適用於FF,Chrome,Opera和Safari。它尚未在IE7或IE8中工作。jQuery驗證不能在IE7 + IE8中工作

下面是我的代碼的簡化版本,似乎在除IE以外的每個瀏覽器都有效。

<!DOCTYPE html> 
<html lang="en"> 
<head> 
<meta charset="utf-8"> 

<title>Form</title> 

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script> 
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.8/jquery.validate.js"></script> 

<script type="text/javascript"> 
    $(document).ready(function(){ 
     var validator = $("form").validate ({ 
     rules: { 
       first_name: "required" 
       }, 
     messages: { 
       first_name: "Enter your firstname" 
       } 
     }); 
    }); 
</script> 

</head> 

<body> 

<form method="post"> 
    <label for="first_name" class="hide">First Name</label> 
    <input type="text" name="first_name" value="" id="first_name" class="required" /> 
    <button type="submit" id="submit" name="submit">Submit</button> 
</form> 

</body> 

</html> 

編輯:我們現在知道,使用jQuery最新的,我是使用jQuery V1.6,是問題。我改回V1.5.2和改變

var validator = $("form").validate ({ 

到:

$("form").validate ({ 

一切工作在IE瀏覽器,現在。謝謝。

+0

向下移動到1.5.2並刪除了「var validator =」,以便我的第一行以$(「form」)。validate開頭。謝謝@redsquare – magzalez 2011-05-10 13:03:31

+0

可能重複的[JQuery驗證在IE8中不起作用](http://stackoverflow.com/questions/3722227/jquery-validation-doesnt-work-in-ie8) – ripper234 2012-02-06 10:13:48

回答

43

我認爲你要麼需要當您在Visual Studio中新的ASP.NET MVC 3項目回遷的jQuery(1.5.2)的早期版本或使用的validation plugin 1.8.0.1.

+0

有沒有辦法可以下載這個沒有nuget? – 2011-05-12 01:37:22

+3

@Kieran Andrews嘗試回購https://github.com/jzaefferer/jquery-validation/ – redsquare 2011-05-12 09:24:16

+0

謝謝!我正在猛撞我的頭... – Antony 2011-06-21 04:08:11

16

較新的版本,你的腳本文件夾在默認情況下在其他包含:

jquery-1.5.1.min.js 
jquery.validate.min.js (which is version 1.8.0) 

一個你可能想要做的第一件事情就是更新jQuery的版本到最新版本,這是當今版本1.7.1

完成此操作後,您的客戶端驗證將在Internet Explorer 7和Internet Explorer 8中停止工作。

這是因爲jquery.validate版本是與jquery版本> 1.6不兼容。解決方案很簡單,您還需要更新jquery.validate的版本。

您可以從微軟的CDN當前版本1.9或從GitHub這裏獲取最新版本:

微軟的Ajax CDN: http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js

GitHub的jQuery驗證: https://github.com/jzaefferer/jquery-validation/downloads

請記住,您始終可以在Microsofts CDN中找到最新的JavaScript庫,請參閱可用庫的完整列表IES這裏:http://www.asp.net/ajaxlibrary/cdn.ashx

這個信息是從我blog post這個問題

+1

感謝您的迴應,這適用於我,我的配置: jQuery 1.9.1和我必須將jQuery Validate從1.15降級到1.9 – RokumDev 2017-01-31 15:55:56

4

我曾與IE7/IE8 jquery.validate.js問題。調試後,我注意到下面一行是導致該問題(LN 436版本1.7):

return $(':input', this.currentForm) 

該訣竅對我來說:

return $([]).add(this.currentForm.elements) 
      .filter(":input") 

這兩條線的東西,如更換。

+0

非常感謝!它像一個魅力。 – 2012-09-14 15:53:13

5

對於它的價值,我不得不升級到最新的JQuery(目前1.8.2)和驗證(1.10)來解決這個問題。

+1

非常感謝! – michele 2014-02-13 12:52:11

+0

@michele歡迎:-) – ozz 2014-02-13 13:14:30

1

我剛剛遇到了這個問題,但問題不是我需要jquery的最新版本 - 這是導致問題的最新版本的jquery。 Jquery 2.x目前不支持IE,因此請確保您使用的是1.8+,但不到2.0。

+0

jQuery 2.0支持IE瀏覽器,但他們已經放棄了所有額外的代碼,只有過時的(破碎)版本才能使jQuery運行得更快。引用http://jquery.com/download:「jQuery 2.x與jQuery 1.x具有相同的API,但不支持Internet Explorer 6,7或8」。 – EpicVoyage 2014-01-14 20:22:18

1

我在使用jqueryui自動完成獲取錯誤「腳本3:成員未找到。jquery-1.8.2.min.js,第2行字符32075」僅在IE(版本10)中使用sage CRM時出現同樣的問題。這個錯誤與頁面模式有關:IE強制網站進入IE 7標準模式。

它是一個討厭的黑客,但它運作良好。把它放在頁面的開頭。我今晚花了一個小時搞砸了這個,希望這可以幫助別人。

<!DOCTYPE HTML> 
<meta http-equiv="x-ua-compatible" content="IE=Edge">