2013-10-07 62 views
1

使用jquery validate插件,我只想在調用元素的模糊事件時顯示/隱藏錯誤,不想在鍵入時顯示錯誤消息。爲了解決這個問題我想Uncaught TypeError:Object#<error> has no method'call'

$('#form').validate({ 
    onfocusout: true, 
    onkeyup: false 
}); 

,但只要我點擊任何元素外,它拋出錯誤

Uncaught TypeError: Object #<error> has no method 'call' 
+1

設置'onfocusout'到TRUE;是_'not有效value'_ [按文檔](HTTP ://jqueryvalidation.org/validate)。 – Sparky

回答

4

onfocusout沒有onfoucusout,更改爲:

$('#form').validate({ 
    onfocusout: function(element) { $(element).valid(); }, 
    onkeyup: function(element) { $(element).valid(); } 
}); 
+0

我錯誤地在這裏輸入!問題已更新。 – coure2011

+0

@ coure2011看到我的更新回答 –

+0

我只需要返回true onkeyup方法,那麼它只適用於onfocusout。非常感謝! – coure2011

1

前面已經指出的Sudhir,你拼錯了onfocusout選項。

此外,onfocusoutonkeyup選項已在此插件中啓用默認

你只有兩種選擇...

1)如果你想禁用onfocusoutonkeyup,你將它們設置爲false ...

$('#form').validate({ 
    onfocusout: false, // disable validation on blur 
    onkeyup: false  // disable validation on key-up 
}); 

2)如果你想修改的onfocusoutonkeyup的默認行爲,你將它們設置爲自定義函數......

$('#form').validate({ 
    onfocusout: function(element, event) { 
     // your custom callback function for blur event 
    }, 
    onkeyup: function(element, event) { 
     // your custom callback function for key-up event 
    } 
}); 

超視距否則,如果您僅僅希望onfocusoutonkeyup選項的默認行爲,則完全不會讓撥打.validate()As per documentation,將它們設置爲true「不是有效值」並且會破壞插件。

$('#form').validate({ 
    // onfocusout: true, // <- remove this line, true value is not valid 
    // onkeyup: true  // <- remove this line, true value is not valid 
}); 

文檔:

onfocusout
Type: Boolean or Function()
Validate elements (except checkboxes/radio buttons) on blur. If nothing is entered, all rules are skipped, except when the field was already marked as invalid. Set to a Function to decide for yourself when to run validation. A boolean true is not a valid value.


onkeyup
Type: Boolean or Function()
Validate elements on keyup. As long as the field is not marked as invalid, nothing happens. Otherwise, all rules are checked on each key up event. Set to false to disable. Set to a Function to decide for yourself when to run validation. A boolean true is not a valid value.

相關問題