douwei1950 2016-05-04 14:55 采纳率: 0%
浏览 25
已采纳

Javascript未在prestashop的产品页面上完全应用

I created a simple module that loads a small form when the user looks at a product in prestashop.

It loads a JS script when the user looks at a product.

The script is getting loaded but many of the functions are not working appropriately. My selectors are right and the script works in one test environment and not in another so I'm a little lost, or maybe I'm missing something simple.

For example - this will run when the page loads (this is part of the JS script loaded by my module):

//disable AddToCart Button unless criteria are met 
function modifyAddToCart(){
    if ($('#customer-confirmation-check').prop('checked')) {
        alert ('customer confirm check');
    $('#add-to-cart-btn').removeClass("toBeCustomized");
    $('#customization-required').text("");
    $('#add-to-cart-btn span').text("Add To Cart");
    $("html, body").animate({ scrollTop: $('#buy_block').offset().top }, 1000);
    } else {
        alert ('should be toBeCustomized');
        console.log(   $('#add-to-cart-btn') );
    $('#add-to-cart-btn').addClass("toBeCustomized");
    $('#add-to-cart-btn span').text("Customize This Item"); 
    $('#customization-required').text("You must customize this product before it can be added to your cart!");
    }
}

The alert is kicked off (that the checkbox hasn't been checked), the console logs the button appropriately - but none of the other things happen. The class is not added, the text is not changed. When I look at it in firebug - I do not see the onClick events being associated with it either.

Is there some sort of system JS script that keeps a modules JS from being applied in certain situations?

Trying to figure out why it works in one situation, but not in another.

  • 写回答

1条回答 默认 最新

  • duan1227 2016-05-04 19:56
    关注

    Turns out there was an option that someone turned on in one environment to load the JS at the bottom of the page (which is the better way to do it).

    That made the difference.

    Advanced Parameters -> Performance -> Move Javascript To End

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统