如何在切换卡片前,清楚卡片动态产生的变量内容

(function(){
  var currentElementID_ChatGPT;  //当前元素ID
  $("#ChatGPT-text div").each(function(index){
      var title = $(this).attr("title");
      var titleID = title+"text"+index;
      var sanitizedTitle = titleID.replace(/\s+/g, '_').replace(/[^a-zA-Z0-9_]/g,'');
  
      const $hoverDiv = $('<div>').addClass('hoverDiv').attr('id', sanitizedTitle +index+ '_hoverDiv');
      $(document).on('dblclick', '#'+sanitizedTitle+index+' .biaozhu', function(e) {
          currentElementID_ChatGPT = sanitizedTitle + index + '_hoverDiv';
          var $hoverDiv = $('#' + currentElementID_ChatGPT);
          $hoverDiv.css('display', 'block');
          var $oneH = $hoverDiv.find('.oneH');
          $oneH.after(newContainer);
      });
  });

})();

怎么清除此值 $hoverDiv, 它在切换卡片后还依然被读取到。因为第二张卡片没有为此变量设置新值,它就返回了前一张卡片的值,这是我不希望的。

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.