代码之家  ›  专栏  ›  技术社区  ›  fightstarr20

jQuery/Javascript-检测woomerce商店通知html是否可见

  •  1
  • fightstarr20  · 技术社区  · 6 年前

    <p class="woocommerce-store-notice demo_store" style="display: block;">
        This is a store notice
    </p>
    

    我试着用以下方法来做这件事。。。

    jQuery(document).ready(function(){
        if ( jQuery('.woocommerce-store-notice').css('display') == 'none') {
            console.log('Store Notice Hidden');
        } else {
            console.log('Store Notice Visible');
        }
    });
    

    但这告诉我,通知每次都是隐藏的,即使它是可见的。

    这可能与商店告示的显示方式有关吗?可能是在dom加载后设置的?

    3 回复  |  直到 6 年前
        1
  •  2
  •   hemnath mouli    6 年前

    当存储通知被禁用时,元素将被移除。CSS display 因此属性不可用 undefined . 试试下面的代码

    jQuery(document).ready(function(){
        if ( jQuery('.woocommerce-store-notice').css('display') == undefined) {
            console.log('Store Notice Hidden');
        } else {
            console.log('Store Notice Visible');
        }
    });
    
        2
  •  0
  •   pixellab    6 年前

    核对

    if(jQuery('.woocommerce-store-notice').is(':visible')){
    
    }
    
    else{
    
    }
    
        3
  •  0
  •   Zysce myrtle303    6 年前