js.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. // ajax get account login info
  20. loginInfoUrl = currentBaseUrl+"/customer/ajax";
  21. logoutUrl = $(".logoutUrl").val();
  22. product_id = $(".product_view_id").val();
  23. product_id = product_id ? product_id : null;
  24. jQuery.ajax({
  25. async:true,
  26. timeout: 6000,
  27. dataType: 'json',
  28. type:'get',
  29. data: {
  30. 'currentUrl':window.location.href,
  31. 'product_id':product_id
  32. },
  33. url:loginInfoUrl,
  34. success:function(data, textStatus){
  35. welcome = $('.welcome_str').val();
  36. logoutStr = $('.logoutStr').val();
  37. if(data.loginStatus){
  38. customer_name = data.customer_name;
  39. str = '<span id="welcome">'+welcome+' '+customer_name+'</span>';
  40. str += '<span id="js_isNotLogin">';
  41. str += '<a href="'+logoutUrl+'" rel="nofollow">'+logoutStr+'</a>';
  42. str += '</span>';
  43. $(".login-text").html(str);
  44. }
  45. if(data.favorite){
  46. $(".myFavorite_nohove").addClass("act");
  47. $(".myFavorite_nohove a").addClass("act");
  48. }
  49. if(data.favorite_product_count){
  50. $("#js_favour_num").html(data.favorite_product_count);
  51. }
  52. if(data.csrfName && data.csrfVal && data.product_id){
  53. $(".product_csrf").attr("name",data.csrfName);
  54. $(".product_csrf").val(data.csrfVal);
  55. }
  56. if(data.cart_qty){
  57. $("#js_cart_items").html(data.cart_qty);
  58. }
  59. },
  60. error:function (XMLHttpRequest, textStatus, errorThrown){}
  61. });
  62. $("#goTop").click(function(){
  63. $("html,body").animate({scrollTop:0},"slow");
  64. });
  65. $("#goBottom").click(function(){
  66. var screenb = $(document).height();
  67. $("html,body").animate({scrollTop:screenb},"slow");
  68. });
  69. });
  70. function doPost(to, p) { // to:提交动作(action),p:参数
  71. var myForm = document.createElement("form");
  72. myForm.method = "post";
  73. myForm.action = to;
  74. for (var i in p){
  75. var myInput = document.createElement("input");
  76. myInput.setAttribute("name", i); // 为input对象设置name
  77. myInput.setAttribute("value", p[i]); // 为input对象设置value
  78. myForm.appendChild(myInput);
  79. }
  80. document.body.appendChild(myForm);
  81. myForm.submit();
  82. document.body.removeChild(myForm); // 提交后移除创建的form
  83. }