开发者

jQuery calling a predefined function

I have a big function defined and executed on an element click. Is there a way to execute again that "big" funct开发者_如何学JAVAion later, call it somehow, without writing it again?

$('#element').click(function(big){
    some big function
    ...
    ...
});


$('#another_element').click(function(){
    this should execute the previous "big" function
});

Thanx.


If you define your function external to the call you can use it as many times as you like.

var bigfunction = function(big) { ... };

$('#element').click(bigfunction);
$('#another_element').click(bigfunction);

You can also declare it the usual way:

function bigfunction(big) { ... };


You should make the "big function" a separated function...

function the_big_function(){
   // do stuff
}

$('#element').click(function(big){
   the_big_function();
});


$('#another_element').click(function(){
    the_big_function();
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜