js.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. $(document).ready(function(){
  2. currentBaseUrl = $(".currentBaseUrl").val();
  3. $(".top_currency .currency_list ul li").click(function(){
  4. currency = $(this).attr("rel");
  5. htmlobj=$.ajax({url:currentBaseUrl+"/cms/home/changecurrency?currency="+currency,async:false});
  6. //alert(htmlobj.responseText);
  7. location.reload() ;
  8. });
  9. $(".top_lang .store_lang").click(function(){
  10. //http = document.location.protocol+"://";
  11. currentStore = $(".current_lang").attr("rel");
  12. changeStore = $(this).attr("rel");
  13. currentUrl = window.location.href;
  14. redirectUrl = currentUrl.replace("://"+currentStore,"://"+changeStore);
  15. //alert(redirectUrl);
  16. //alert(2);
  17. location.href=redirectUrl;
  18. });
  19. $(window).scroll(function () {
  20. var currentscrollTop = $(document).scrollTop();
  21. var top = $(".main-container").offset().top; //当前box3距离窗口顶部的距离
  22. if( currentscrollTop > top){
  23. $("#header").addClass("header_fixed");
  24. }
  25. if(currentscrollTop == 0){
  26. $("#header").removeClass("header_fixed");
  27. }
  28. });
  29. // ajax get account login info
  30. loginInfoUrl = currentBaseUrl+"/customer/ajax";
  31. logoutUrl = $(".logoutUrl").val();
  32. product_id = $(".product_view_id").val();
  33. product_id = product_id ? product_id : null;
  34. jQuery.ajax({
  35. async:true,
  36. timeout: 6000,
  37. dataType: 'json',
  38. type:'get',
  39. data: {
  40. 'currentUrl':window.location.href,
  41. 'product_id':product_id
  42. },
  43. url:loginInfoUrl,
  44. success:function(data, textStatus){
  45. welcome = $('.welcome_str').val();
  46. logoutStr = $('.logoutStr').val();
  47. if(data.loginStatus){
  48. customer_name = data.customer_name;
  49. str = '<span id="welcome">'+welcome+' '+customer_name+'</span>';
  50. str += '<span id="js_isNotLogin">';
  51. str += '<a href="'+logoutUrl+'" rel="nofollow">'+logoutStr+'</a>';
  52. str += '</span>';
  53. $(".login-text").html(str);
  54. }
  55. if(data.favorite){
  56. $(".myFavorite_nohove").addClass("act");
  57. $(".myFavorite_nohove a").addClass("act");
  58. }
  59. if(data.favorite_product_count){
  60. $("#js_favour_num").html(data.favorite_product_count);
  61. }
  62. if(data.csrfName && data.csrfVal && data.product_id){
  63. $(".product_csrf").attr("name",data.csrfName);
  64. $(".product_csrf").val(data.csrfVal);
  65. }
  66. if(data.cart_qty){
  67. $("#js_cart_items").html(data.cart_qty);
  68. }
  69. },
  70. error:function (XMLHttpRequest, textStatus, errorThrown){}
  71. });
  72. $("#goTop").click(function(){
  73. $("html,body").animate({scrollTop:0},"slow");
  74. });
  75. $("#goBottom").click(function(){
  76. var screenb = $(document).height();
  77. $("html,body").animate({scrollTop:screenb},"slow");
  78. });
  79. });
  80. function doPost(to, p) { // to:提交动作(action),p:参数
  81. var myForm = document.createElement("form");
  82. myForm.method = "post";
  83. myForm.action = to;
  84. for (var i in p){
  85. var myInput = document.createElement("input");
  86. myInput.setAttribute("name", i); // 为input对象设置name
  87. myInput.setAttribute("value", p[i]); // 为input对象设置value
  88. myForm.appendChild(myInput);
  89. }
  90. document.body.appendChild(myForm);
  91. myForm.submit();
  92. document.body.removeChild(myForm); // 提交后移除创建的form
  93. }