Stop jQuery from repeating, example attached

随声附和 提交于 2019-12-01 14:19:12

Change your repeating template to include a check:

<script>
if (typeof alreadyDone === "undefined") {
   var alreadyDone = true;

   $(document).ready(function() {
     $('td.barcode_needed').append('<div class="bcTarget">');

     $('.bcTarget').each(function() {
       var $this = $(this);
       $this.barcode('G' + $this.closest('td.barcode_needed').text(),'code128');
     });    
   });
}
</script>

Now it should run only once.

Another thing to try, where we remove the classes as we go...

<script>
 $('td.barcode_needed').each(function() {
       $(this).append('<div class="bcTarget">');
 });

 $('.bcTarget').each(function() {
   $(this).barcode('G' + $(this).closest('td.barcode_needed').text(),'code128');
   $(this).removeClass('bcTarget');       
   $(this).closest('td.barcode_needed').removeClass('barcode_needed');
 });    
</script>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!