Jquery 'or' statement?
I would like for a text box to disappear if a p开发者_如何学JAVAerson clicks out side of it (.focusout or .blur) but I also want to be able do the same function if Esc is pressed (key 27). I am not sure how to get both to be recognized without ruining my entire script.
You can bind both events to the same function with
$(selector).bind("blur keyup",function(e){...})
And then it's just decision logic to see if it was a key that was pressed or whatnot.
How about something like this:
$('#selector').bind('blur keyup', function(e) {
if(e.keyCode == 27 || e.keyCode == undefined)
$(this).hide();
});
I would create a custom event bound to the text box:
<script>
$(document).ready(function(){
$("#id").bind("blur keyup myCustomEvent"),function(event){
//whatever you need
// you can trigger this logic again via .trigger("myCustomEvent");
});
});
</script>
精彩评论