开发者

jQuery Call a Function in Addition to some other code

I'm trying to call a function into another function to get rid of some redundant code. The 'test' function is a standard piece of repetitive code, so I don't want to keep writing it out along with the custom animation.

(function test() {
    do this
});    

/* =========================Standard code========================= */
$(function () {
$('#div').click(EXECUTE THE 'TEST' FUNCTION HERE AND THEN...function() {
    $('#timeline').stop().animate({
        left : "+=500px"
    });
});

});

Here is the solution thanks to the kind guys below:

开发者_JAVA技巧function test() {
    do this
}

/* =========================Standard code========================= */
$(function () {
$('#div').click(function() {
    test();
    $('#timeline').stop().animate({
        left : "+=500px"
    });
});


Is there anything wrong with:

$(function () {
$('#div').click(function() {
    test();
    $('#timeline').stop().animate({
        left : "+=500px"
    });
});

??


You would put your call to test() above the $('#timeline').... line.


why you are using round braces around the test() function?

Can you try with an ALERT box in test() function?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜