开发者

jquery combine event functions

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        

    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜