2011-12-02 104 views
2

添加多个功能我也这样与它工作正常:

$(document).ready(
    highlightTableRow 
); 

,但是当我添加第二个函数(见下文),第二没有按”工作。

$(document).ready(
    highlightTableRow, 
    attachClickLinkHandlerForRowLink 
); 

什么是添加第二个函数到我的就绪函数的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** 
+3

添加括号()和分号;你的函数调用后 – Evan

+1

所有的答案都是一样的..他们应该是.. – AlphaMale

+1

@AlphaMale你不会相信它...有些答案是勘误maximus;)(现在修复...我希望...)8D –

回答

9

你可以做

$(document).ready(function() { 
    highlightTableRow(); 
    attachClickLinkHandlerForRowLink(); 
}); 

你也可以改变$(document).ready()部分进入$(function()所以你会得到

$(function() { 
    highlightTableRow(); 
    attachClickLinkHandlerForRowLink(); 
}); 

做同样的唯一短

+0

你赢了(最快):) +1 – 2011-12-02 17:13:18

+0

@RC。哈哈thnx! –

+0

恭喜!呃..这是一场比赛! ; D –

3

我会做这样的事情:

$(document).ready(function() 
{ 
    highlightTableRow(); 
    attachClickLinkHandlerForRowLink(); 

}); 

我缺少重点吗?

+0

错过了功能部分 –

+0

@Joseph:我加了:P谢谢! – Icarus

3

为什么你不这样使用?

$(document).ready(function(){ 
    highlightTableRow(); 
    attachClickLinkHandlerForRowLink(); 
}); 
+0

感谢罗布,有时代码功能不能完美的工作。 – tildy

4

试样:

$(document).ready(function(){ 
    highlightTableRow(); 
    attachClickLinkHandlerForRowLink(); 
}); 
+0

+1你右回 –

2

document.ready需要函数

$(document).ready(function() { 
    highlightTableRow(); 
    attachClickLinkHandlerForRowLink(); 
}); 
+1

不应该第一个只是调用attachClickLinkHandlerForRowLink? –

+0

@约瑟夫 - 是的,谢谢。 –

+0

+1 ...我们所有人都收到了选票......如果你不像我们中的大多数人那样得到2分,那将是愚蠢的! :D:D –

相关问题