簡體   English   中英

單擊另一個按鈕時重置切換

[英]Reset toggle on click of another button

如何重置正在進行的切換?

下面是我正在使用的代碼,在最后的注釋中,我定義了我需要的代碼。

(function($) {
  $.fn.clickToggle = function(func1, func2) {
    var funcs = [func1, func2];
    this.data('toggleclicked', 0);
    this.click(function() {
      var data = $(this).data();
      var tc = data.toggleclicked;
      $.proxy(funcs[tc], this)();
      data.toggleclicked = (tc + 1) % 2;
    });
    return this;
  };
}(jQuery));

function showTakeNotes() {
  // some functions will here while SHOWING the notes
}

function hideTakeNotes() {
  // some functions will here while HIDING the notes
}

// Capturing the toggleClick event of '.btn-show-hide-take-slide-note'
$('.btn-show-hide-notes').clickToggle(function() {
  showTakeNotes();
}, function() {
  hideTakeNotes();
});

// there is another close button within the Notes widow to close the window
$(".btn-close-take-notes").clickToggle(function() {
  hideTakeNotes();
}, function() {
  // HERE I LIKE TO RUN RESET EVENT THAT'S ALREADY RECORDED WHILE SHOWING THE NOTES WINDOW .btn-show-hide-notes
});

toggleclicked數據控制哪個功能。 如果要將其重置以調用showTakeNotes函數。 您可以使用

 $('.btn-show-hide-notes').data('toggleclicked', 0);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM