简体   繁体   English

在页面加载时调用jQuery函数

[英]Calling jQuery functions on pageload

b.delegate(".uipro_open_left", "click", function(){$.uiPro.open("left")});
b.delegate(".uipro_open_right", "click", function(){$.uiPro.open("right")});

I would like to call these two on page load. 我想在页面加载时称呼这两个。 How could I do that? 我该怎么办? Thank you in advance for your reply. 预先感谢您的答复。 :) :)

There are 2 ways of doing it 有两种方法

$(document).ready(function(){
    //your function
});

or simply 或简单地

$(function(){
    //your function
});

Read window.onload vs $(document).ready() to get a clear understanding of when you need to call you functions. 阅读window.onload与$(document).ready()可以清楚地了解何时需要调用函数。

Correcting your grammar, your functions would be called when that element will be clicked on the page. 更正语法后,当在页面上单击该元素时,将调用您的函数。 Enclosing your function definition in the snippet I have mentioned will ensure that these are invoked only when your DOM is ready. 我提到的代码中包含了函数定义,这将确保仅在DOM准备就绪时才调用它们。

Sorry to say this but you have a steep learning curve ahead so get started ASAP. 抱歉,您的学习曲线很陡峭,所以请尽快开始。

You can use $( document ).ready() function. 您可以使用$(document).ready()函数。

$( document ).ready(function() {
    console.log( "ready!" );
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM