首页 > 解决方案 > WooCommerce 中超出了最大调用堆栈大小

问题描述

我在这里有这个 HTML 结构:

<li class="description_tab" id="tab-title-description" role="tab" aria-controls="tab-description">
      <a href="#tab-description">Description</a>
</li>

这是我的 JS 函数:

jQuery('body.woocommerce div.product .woocommerce-tabs ul.tabs li').click(function () {
    jQuery('a', this).click();
});

我试图做的是检查标签是否被点击。如果这是真的,我将触发单击选项卡的内部。但是当我加载页面时出现错误:

未捕获的 RangeError: 在新的
a.fn.init (jquery-migrate.min.js?ver=1.4 .1:2) 在 HTMLLIElement 的 n (jquery.js?ver=1.12.4:2) 。(custom.js?ver=4.9.8:77) 在 HTMLLIElement.dispatch (jquery.js?ver=1.12.4:3) 在 HTMLLIElement.r.handle (jquery.js?ver=1.12.4:3) 在HTMLAnchorElement 中的 Object.a.event.trigger (jquery-migrate.min.js?ver=1.4.1:2)中的Object.trigger (jquery.js?ver=1.12.4:3) 。(jquery.js?ver=1.12.4:3)








怎么了?

标签: jqueryhtmlwoocommerce

解决方案


这就是它现在的工作方式。工作但有很多代码:

jQuery('body.woocommerce div.product .woocommerce-tabs ul.tabs li').click(function () {
        var description = jQuery('.woocommerce-Tabs-panel--description');
        var reviews = jQuery('.woocommerce-Tabs-panel--reviews');
        if (!jQuery(this).hasClass('active')) {
            if (jQuery(this).hasClass('reviews_tab')) {
                jQuery('.description_tab').removeClass('active');
                jQuery(this).addClass('active');
                description.hide();
                reviews.show();
            } else if (jQuery(this).hasClass('description_tab')) {
                jQuery('.reviews_tab').removeClass('active');
                jQuery(this).addClass('active');
                reviews.hide();
                description.show();
            }
        }
    });

我不知道我是否可以做得更好。


推荐阅读