AJAX/page refresh kills JS/jQuery

AJAX/page refresh kills JS/jQuery

本文关键字:JS jQuery kills refresh page AJAX      更新时间:2023-09-26

我正在进行A/B测试(将代码注入页面)以增加购物车中产品的图像。

当您选择其他运输方式时,整个表格似乎已刷新。

我的代码只会在第一次执行。

因此,当我第二次选择不同的运输方式时。 我的代码丢失了。

除了标签保留。

您需要在购物车中随机放置一个产品才能首先看到它。

<script>
$( document ).ready(function() {
 $('img.item-img').each(function() {
    var str      = $(this).attr('src'),
        arr      = str.split("?");
		query	 = "?hei=200&wid=200&op_sharpen=1"
    $(this).attr('src', arr[0] + query);
});
  
  $( document ).ready(function() {
    $('tr').each(function() {
  var desc = $('td.description', this).html() 
  $('td.image', this).append(desc);
  $('td.description', this).remove();
});
  $("table#shopping-cart-items tr td.image").after($('<td id="clearSpace"></td>'));
});
});
  
  </script>

<script>
  
  
  $( document ).ready(function() {
    $('div.shippingOpt').click(function() {
		
		
   window.setTimeout(function(){  
 
	
	 $('img.item-img').each(function() {
    var str      = $(this).attr('src'),
        arr      = str.split("?");
		query	 = "?hei=200&wid=200&op_sharpen=1"
    $(this).attr('src', arr[0] + query);
});
	
   $('tr').each(function() {
  var desc = $('td.description', this).html() 
  $('td.image', this).append(desc);
  $('td.description', this).remove();
});
                     
  $("table#shopping-cart-items tr td.image").after($('<td id="clearSpace"></td>'));
     
          }, 1000);           
                    });
});
  </script>
<style>
    .checkoutBasket table.cart-container td.image img { width:200px; height:auto;}
  
	#clearSpace  {padding: 0 0 0 15px;}
</style>

请使用以下代码:

$('div.shippingOpt').on('click', function(){{...});