2011-06-08 58 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

相关问题