問題描述
我正在使用 jQuery 驗證插件 v.1.9.0 它可以工作很友好地.但是我面臨這個問題,一旦用戶提交表單 &如果有任何錯誤,它會正確顯示錯誤消息.問題在于,如果用戶采取措施糾正該錯誤,它不會更新消息.例如.如果需要一個字段,則在第一次收到消息時,用戶開始輸入,然后該消息應該消失.
I am using jQuery Validate plugin v.1.9.0 it works very nicely. But I am facing this issue, once the user submits the form & if there are any errors, it correctly display error message. The problem is that it does not update the message if the user takes an action to remedy that error. E.g. if a field is required, upon getting the message the first time, user starts typing, then that message should go away.
在文檔中提到 onfocusout &onkeyup 用于此目的 &默認情況下,它們設置為 true.有趣的是,它似乎可以在我的本地工作站上運行,但是一旦我將代碼上傳到生產站點,它就會(默默地)失敗.我以為我以某種方式把它搞砸了,所以我啟動了 jsfiddle 并輸入了相關代碼 看看它是否也發生在那里.
In the docs it mentions that onfocusout & onkeyup are used for this purpose & by default they are set to true. The funny thing is it seems to work on my local workstation but it fails (silently) once I upload my code to production site. I thought I was messing it up royally somehow so I fired up jsfiddle and put relevant code to see if it happens there as well.
我很驚訝地看到它也發生在那里.所以我的問題是為什么它可以在我的本地機器上運行,但不能在生產站點上運行?
I was amazed to see it happens there as well. So my question is why does it work on my local machine but not on production sites?
附:http://jsfiddle.net/tankchintan/cge44/5/的獨立示例
更新
要復制問題,請執行 -
To replicate the issue, do -
- 轉到 jsfiddle 頁面.
- 無需填寫任何字段點擊提交表單.
- 它會在每個字段旁邊顯示錯誤消息.
- 現在開始在任一字段中輸入內容.
- 您會注意到,即使滿足規則,錯誤消息也不會消失.在我的本地機器上,一旦我在該字段中輸入任何內容,錯誤消息就會消失.
推薦答案
這個問題甚至在JQuery網站的一些例子中也存在.
This problem even exists in some of the examples on the JQuery website.
我發現當輸入元素沒有類型時會出現問題.如果未指定,Web 瀏覽器假定類型為文本",但 jquery.validate 存在問題.您的輸入元素應如下所示:
I found that the problem occurs when the input element has no type. Web browsers assume that the type is "text" if not specified, but jquery.validate has a problem with that. Your input element should look like this:
<input id="cname" name="name" type="text" class="required" minlength="2" />
這篇關于使用 jQuery 驗證插件:onfocusout、onkeyup 在生產站點上未按預期工作的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!