Two trigger to one function ? [keyup and focusout]
Welcome,
I have function
$('#myfield').keyup(function () { //do something }
//- do something is runing when user write something in myfield. I notice, when user use "auto complete" from browser, my function is not executed.
I found idea, to use focusout
Do you have any idea ho开发者_StackOverflow中文版w can i combine that code together, without writing second function like this ?
$('#myfield').focusout(function () { //do something }
I would like to put this 2 functions together, and don't write //do something, two times.
regards
You can use .bind()
which takes a space separated list of events to bind your handler to, like this:
$('#myfield').bind("keyup focusout", function () {
//do something
});
Though, unless you need some special propagation, I'd stick with blur
over focusout
, just a preference really:
$('#myfield').bind("keyup blur", function () {
//do something
});
bind multiple events to input box
$('#myfield').bind("focusout",function(){
})
you can also write function seperately and give function name alone.. like...
$('#myfield').keyup(function_name).focusout (function_name);
function function_name() {
//do something
}
精彩评论