简体   繁体   English

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

[英]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.

相关问题 如何调用jQuery函数,使其可以在document.ready函数中运行? - How do I call my jQuery function so that it will run in my document.ready function? 如何将$(document).ready(function()添加到joomla - How do you add $(document).ready(function() to joomla 如果多个用户控件注册$(document).ready函数会发生什么? - What happens if more than one user control registers $(document).ready function? 如何将一个函数的值转换为文档准备就绪? - How can I get the value from one function into document ready? 我必须在外部脚本中包含$(document).ready(function()多少次 - how many times do I have to include the $(document) .ready (function() in my external script 我还需要$(document).ready(function(){})吗? - Do I still need $(document).ready(function(){ })? 如何获得ready函数和另一个可以在document.ready中正常播放的函数? - How do I get a ready function and another function to play nicely in document.ready? 如何为我的函数添加更多参数? - How do I add more arguments to my function? 如果我使用 jQuery(document).ready(function(){ ... my code}) = undifined function - If i use jQuery(document).ready(function(){ … my code}) = undifined function 在文档就绪时执行 Ajax 功能 - Do Ajax function on document ready
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM