2011-06-08 57 views
0

我有一個需要驗證的簡單表單。我已經在FF中工作,但它在IE中的表現很奇怪。我正在使用jQuery 1.6和jQuery Validate 1.8。未在IE中運行的jQuery驗證(在FF中工作)

以下是完整的html代碼。正如你所看到的,我已經嘗試過改變charset屬性,因爲我讀過一些人爲IE做這件事。仍然沒有運氣。奇怪的是,當你在IE中運行這個時,submitHandler會被觸發(顯示的警報表明表單已被提交)。就好像驗證函數根本不會關閉,即使整個表單留空。有人可以嘗試這個或建議一個解決方案?

<html> 

<head> 

<script src="jquery.min.js" type="text/javascript" charset="ISO-8859-1"></script> 
<script src="jquery.validate.min.js" type="text/javascript" charset="ISO-8859-1"></script> 

<script> 
$(document).ready(function() { 

    var prospectTxErrors = { 
     prospectName : { 
      required : "An entry is required in field Prospect.", 
      rangelength : "Prospect Name must be between 2 and 45 characters." 
      }, 
     groupSize : { 
      required : "An entry is required in field Group Size.", 
      digits : "Numeric data is required in field Group Size." 
     }, 
     zipCode : { 
      required : "An entry is required in field Zip Code.", 
      digits : "Numeric data is required in field Zip Code.", 
      rangelength : "Zip Code must be 5 digits." 
     }, 
     sicCode : { 
      required : "This is an invalid SIC code. Enter the SIC again or search for the SIC code.", 
      rangelength : "This is an invalid SIC code. Enter the SIC again or search for the SIC code.", 
      digits : "This is an invalid SIC code. Enter the SIC again or search for the SIC code." 
     }, 
     agencyProducer : { 
      required : "An entry is required in the Agent field." 
     }, 
     phone : { 
      required : "A 10 digit entry is required for Phone field." 
     } 
    }; 

    $.validator.setDefaults({ 
     submitHandler : function() { alert("submitted!"); } 
    }); 

    $("#prospectForm").validate({ 
     errorLabelContainer : $("#errorDiv ul"), 
     wrapper : "li", 
     debug : true, 
     rules : { 
      prospectName : { 
       required : true, 
       rangelength : [2, 45] 
      }, 
      groupSize : { 
       required : true, 
       digits : true 
      }, 
      zipCode : { 
       required : true, 
       digits : true, 
       rangelength : [5, 5]  
      }, 
      sicCode : { 
       required : true, 
       rangelength : [4, 4], 
       digits : true 
      }, 
      agencyProducer : { 
       required : true 
      }, 
      phone : { 
       required : true, 
       digits : true 
      } 
     }, 
     messages : prospectTxErrors 
    }); 
}); 
</script> 

<title>Test Prospect</title> 
</head> 

<body> 

<div id="errorDiv"><ul id="errorList"></ul></div> 

<form class="prospectForm" id="prospectForm" method="get" action=""> 
<label>Prospect Name</label> 
<input type="text" 
    name="prospectName" 
    id="prospectName" 
    class=""/> 
<br></br> 
<label>Group Size</label> 
<input type="text" 
    name="groupSize" 
    id="groupSize" 
    class=""/> 
<br></br> 
<label>Zip Code</label> 
<input type="text" 
    name="zipCode" 
    id="zipCode" 
    maxLength="5" 
    class=""/> 
<br></br> 
<label>SIC Code</label> 
<input type="text" 
    name="sicCode" 
    id="sicCode" 
    maxLength="4" 
    class=""/> 
<br></br> 
<label>Agency/Producer</label> 
<input type="text" 
    name="agencyProducer" 
    id="agencyProducer" 
    class=""/> 
<br></br> 
<label>Phone</label> 
<input type="text" 
    name="phone" 
    id="phone" 
    class=""/> 
<input class="submit" type="submit" value="Submit"/> 

</form> 

</body> 
</html> 

回答

2

jQuery Validation not working in IE7 + IE8

看到這個前面回答的問題。同樣的問題,也可能在這裏工作。

+0

何塞,原來我用的.js文件中的一個不知何故被損壞。我不知道爲什麼它只會導致一個IE問題,但是當我下載了jquery.validate.js文件的新版本,瞧,它工作。謝謝你的幫助。 – dannymac21 2011-06-10 13:02:38

0

沒有必要更改整個jquery版本..只是更新您的jquery.validate版本爲1.9 ...這是因爲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

相關問題