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

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

报告相同问题?

悬赏问题

  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3