jQuery结合了.ready和.resize函数 [英] jQuery combine .ready and .resize functions
本文介绍了jQuery结合了.ready和.resize函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
正如标题所述,我在两个函数中都需要运行完全相同的代码.有没有一种方法可以将它们组合在一起并作为一个功能运行?谢谢!
As the title says, I have exactly the same code needs to run in both functions. Is there a way to put them together and run as one function please? Thanks!
推荐答案
是.只需使用通用代码定义一个函数,并将其作为参数传递给这两个方法.
Yes. Simply define a function with the common code and pass that as the argument to the two methods.
var callback = function () {
// This is the common code
};
$(document).ready(callback);
$(window).resize(callback);
这篇关于jQuery结合了.ready和.resize函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文