instead of example:
$(".myfield").blur(fun开发者_开发知识库ction() {
// validate
})
$(".myfield").keyup(function() {
// validate
})
is there a way to combine these two?
Yes
$(".myfield").bind('blur keyup', function(){
// validate
});
Reference: .bind()
In case you want to validate each for itself...
$('.myfield').live('blur keyup', function(event) {
if (event.type == 'blur') {
// validate on blur
}
if (event.type == 'keyup') {
// validate on keyup
}
});
use with .on() Event
$(document).on("keyup blur", "#myfield", function(event)
{
// your code
});
精彩评论