javascript - How to wrap existing event handler without modifying "this"? -
javascript - How to wrap existing event handler without modifying "this"? -
i using existing code has form submit handler:
function ajaxformsubmit(e) { [...] var form = $(this); [...] }
to bind handler in view code have this:
$('myform').submit(ajaxformsubmit);
what want run other code before calling ajaxformsubmit this:
$('myform').submit(function(e) { dosomething(); ajaxformsubmit(e); });
the problem in ajaxformsubmit, phone call $(this) doesn't form element. best way accomplish this?
you need sure this
gets called in right context.
$('myform').submit(function(e) { dosomething(); ajaxformsubmit.call(this, e); });
javascript jquery
Comments
Post a Comment