加载后的jQuery调用函数 [英] jQuery call function after load
问题描述
Need to call a filter function on some options based on a radio selected (Link here), How can I call this after the page is loaded? the radio is set from a DB call and I would like to filter the options
推荐答案
$(document).ready(my_function);
或
$(document).ready(function () {
// Function code here.
});
或更短但不易理解的变体:
Or the shorter but less readable variant:
$(my_function);
所有这些都会导致DOM加载后调用my_function.
All of these will cause my_function to be called after the DOM loads.
有关更多详细信息,请参见就绪事件文档.
See the ready event documentation for more details.
绑定要执行的功能 每当DOM准备就绪时 遍历和操纵.
Binds a function to be executed whenever the DOM is ready to be traversed and manipulated.
要模拟点击,请使用不带参数的click()方法:
To simulate a click, use the click() method without arguments:
$('#button').click();
从文档:
触发每个点击事件 匹配的元素.导致所有 已经绑定到的功能 点击事件要执行.
Triggers the click event of each matched element. Causes all of the functions that have been bound to that click event to be executed.
将它们放在一起,下面的代码模拟了文档加载完成后的点击:
To put it all together, the following code simulates a click when the document finishes loading:
$(function () {
$('#button').click();
});
这篇关于加载后的jQuery调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!