2011-11-21 42 views
1

我想使用jQuery驗證插件添加客戶端驗證。在Firefox和Chrome中,這可以正常工作。jQuery驗證不會阻止在IE中提交

在IE中,驗證顯示爲錯誤,但表單提交不會停止。爲什麼會發生這種情況?

示例代碼:

<form class="cmxform" id="commentForm" method="get" action=""> 
<fieldset> 
    <legend>A simple comment form with submit validation and default messages</legend> 
    <p> 
     <label for="cname">Name</label> 
     <em>*</em><input id="cname" name="name" size="25" class="required" minlength="2" /> 
    </p> 
    <p> 
     <label for="cemail">E-Mail</label> 
     <em>*</em><input id="cemail" name="email" size="25" class="required email" /> 
    </p> 
    <p> 
     <label for="curl">URL</label> 
     <em> </em> 
     <input id="curl" name="url" size="25" class="url" value="" /> 
    </p> 
    <p> 
     <label for="ccomment">Your comment</label> 
     <em>*</em> 
     <textarea id="ccomment" name="comment" cols="22" class="required"></textarea> 
    </p> 
    <p> 
     <input class="submit" type="submit" value="Submit"/> 
    </p> 
</fieldset> 
</form> 

而且JS

$("#commentForm").validate(); 

這是http://docs.jquery.com/Plugins/Validation直取的例子,其中我猜想應該可行,但似乎並沒有爲IE(我正在使用IE 8測試XP)

+1

對不起,我把我的通靈褲留在家中。你能否發佈導致問題的代碼? –

+1

確保你在驗證時返回false – Tigra

+0

@Tigra如果jquery驗證插件配置正確,那不是必需的。 –

回答

1

我使用的是jQuery版本1.7,它不受版本1.9支持的驗證插件的影響,回退到版本1.6.1修復了這個問題。