2016-05-04 14:55
浏览 25


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 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 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.

图片转代码服务由CSDN问答提供 功能建议



脚本已加载,但许多功能无法正常工作。 我的选择器是正确的,脚本在一个测试环境中工作,而不是在另一个测试环境中,所以我有点迷失,或者我可能会遗漏一些简单的东西。

例如 - 这将运行 当页面加载时(这是我的模块加载的JS脚本的一部分):

function modifyAddToCart(){
 if  ($('#customer-confirmation-check')。prop('checked')){
 alert('customer confirm check'); 
 $('#add-to-cart-btn')。removeClass(  “toBeCustomized”); 
 $('#add-to-cart-btn span')。text(“Add to Cart”); \  n $(“html,body”)。animate({scrollTop:$('#buy_block')。offset()。top},1000); 
} else {
 alert('应该是toBeCustomized'); \  n console.log($('add-to-cart-btn')); 
 $('#add  -to-cart-btn span')。text(“Customize This Item”);  

启动警报(未选中复选框),控制台正确记录按钮 - 但其他任何事情都没有发生。 未添加该类,文本未更改。 当我在firebug中查看它时 - 我也没有看到onClick事件与它相关联。

是否存在某种系统JS脚本使得模块JS不能被应用于某些 情况呢?


  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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

    打赏 评论

相关推荐 更多相似问题