如何在$(document).ready函数中添加多个函数

Dal*_*ale 2 javascript jquery

我有这个,它工作正常:

$(document).ready(
    highlightTableRow
);
Run Code Online (Sandbox Code Playgroud)

但是当我添加第二个函数(见下文)时,第二个函数不起作用.

$(document).ready(
    highlightTableRow,
    attachClickLinkHandlerForRowLink
);
Run Code Online (Sandbox Code Playgroud)

将第二个函数添加到ready函数的correnct语法是什么?谢谢.

编辑:添加语法错误.(日食)

$(document).ready(
    highlightTableRow();  **// error:Syntax error, insert ")" to complete Arguments**
    attachClickHandlerForRowLink();  **//error: Missing semicolon**
); **// error: Syntax error on token ")", delete this token**


var originalRowBackground;

function highlightTableRow(){
    $('[class^="contentRow"]:has(a)').live('mouseenter', enterRowFunction).live('mouseleave', exitRowFunction);
}

function enterRowFunction(){
    originalRowBackground = $(this).css('background-color');
    $(this).css({'background-color': "#EFE3FF", 'cursor': 'pointer'});
}

function exitRowFunction(){
    $(this).css({'background-color': originalRowBackground, 'cursor': 'pointer'});
}

function attachClickHandlerForRowLink(){
    $('[class^="contentRow"]:has(a)').live('click', clickRowLink);
}

function clickRowLink(){
    window.location = $(this).find("a").attr("href");
}    **//error: Missing semicolon**
Run Code Online (Sandbox Code Playgroud)

Man*_*ijn 9

你能做到的

$(document).ready(function() {
    highlightTableRow();
    attachClickLinkHandlerForRowLink();
});
Run Code Online (Sandbox Code Playgroud)

你也可以将$(document).ready()部分改成$(function()你想要的

$(function() {
    highlightTableRow();
    attachClickLinkHandlerForRowLink();
});
Run Code Online (Sandbox Code Playgroud)

同样只是更短