首页 > 解决方案 > 需要帮助组合 jQuery 函数

问题描述

就像标题说的那样,我需要一些帮助来组合两个 jQuery 函数。这似乎很简单,但我无法弄清楚。他们每个人都做同样的事情。如果有帮助,第二个函数的“updated_checkout”是一个 WooCommerce 回调。

$( window ).on( 'resize', function () {
     // Do same thing as other function
});

jQuery( document ).on( 'updated_checkout', function () {
     // Do same thing as other function
} );

标签: javascriptjquerywoocommerce

解决方案


简单如:

function doTheSameThing() {
    // Do same thing
}

$( window ).on( 'resize', doTheSameThing);

jQuery( document ).on( 'updated_checkout', doTheSameThing);

推荐阅读