2013-01-17 37 views
8

我有這樣的代碼:jquery,如何知道什麼時候輸入有一個:無效的選擇器?

HTML

<input type="text" data-value="1" data-type="input-records" placeholder="Value" pattern="\d{1,4}$" /> 

CSS

input[type=text]:invalid { background-color: red; } 

的Javascript

$("[data-type=input-records]").die().live("keypress", function (e) { 
    if (!($(this).val().length + 1) < 5) { 
     e.preventDefault(); 
     return; 
    } 

    // More code below... 
}); 

我要讓這樣的驗證:

if (!$(this).hasSelector(":invalid")) { 
    showMessage("Invalid value"); 
} 

回答

相關問題