[英]How do I add more than one function in my $(document).ready function
I have this and it works fine: 我有这个,它工作正常:
$(document).ready(
highlightTableRow
);
but when I add a second function (see below) the second doesn't work. 但是当我添加第二个函数(见下文)时,第二个函数不起作用。
$(document).ready(
highlightTableRow,
attachClickLinkHandlerForRowLink
);
What's the correnct syntax for adding a second function to my ready function? 将第二个函数添加到ready函数的语法是什么? Thanks.
谢谢。
edit: add syntax errors. 编辑:添加语法错误。 (eclipse)
(日食)
$(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**
you could do 你能做到的
$(document).ready(function() {
highlightTableRow();
attachClickLinkHandlerForRowLink();
});
also you could change the $(document).ready()
part into $(function()
so you would get 你也可以将
$(document).ready()
部分更改为$(function()
这样你就可以得到
$(function() {
highlightTableRow();
attachClickLinkHandlerForRowLink();
});
does the same only shorter 同样只是更短
try like: 尝试像:
$(document).ready(function(){
highlightTableRow();
attachClickLinkHandlerForRowLink();
});
I would do something like this: 我会做这样的事情:
$(document).ready(function()
{
highlightTableRow();
attachClickLinkHandlerForRowLink();
});
Am I missing the point? 我错过了这一点吗?
Why don't you use like this? 你为什么不这样用?
$(document).ready(function(){
highlightTableRow();
attachClickLinkHandlerForRowLink();
});
document.ready
takes a function document.ready
需要一个功能
$(document).ready(function() {
highlightTableRow();
attachClickLinkHandlerForRowLink();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.