2013-05-08 55 views
1

我使用webshim檢查兩個文本輸入中是否有文本,並認爲自定義有效性聽起來正確。 http://afarkas.github.io/webshim/demos/demos/webforms/4-webforms-custom-validity.html運行webshim「addCustomValidityRule」

有一個名爲addCustomValidityRule方法,看起來像這樣:

$.webshims.addCustomValidityRule('testname', function (elem, value) { 
    if (value && $(elem).hasClass('test-class') && value != 'foo bar baz') { 
     return true; //means yes, it's not valid 
    } else { 
     return false; //no, it is valid 
    } 
}, 'you have to enter foo bar baz'); 

但我無法找到任何方式來觸發它。我如何觸發或運行「提交點擊」?

回答

1

@大衛拉爾森

HTML5表單驗證使用setCustomValidityŧ o使用customError將輸入標記爲無效。 Unfortunatley一個領域被儘快標記爲無效(提交事件爲時已晚)。

這意味着,如果您使用此助手addCustomValidityRule,它將立即在所有輸入,select和textarea元素上運行該函數,並且如果它檢測到更改。 (改變事件)。

如果您想調用此函數,只需在給定元素上觸發事件'refreshCustomValidityRules'即可。

相關問題