2012-08-24 37 views
4

這裏就是我定義我認爲事件:jQuery Mobile的+骨幹龍頭事件觸發兩次

events : { 
      "tap #exerciseProgressBarContainer" : 'progressBarClick' 
     }, 

這裏是動作:

progressBarClick : function() { 
     // start? 
     if(this.curWorkoutExercise.isTimed() && !this.curExerciseStartTime) { 
      HTMLHelper.endGlow(this.$('#exerciseProgressBarContainer .progressBar.overlay')); 
      this.startExerciseProgressTimer(); 
     } 
     // done? 
     else { 
      this.stopExerciseProgressTimer(); 

      // save the log 
      this.addCurExerciseLog(); 

      this.startBreak(); 
      this.nextAction(); 
     } 
    }, 

基本上,第一個水龍頭,用戶啓動進度計時器,並在啓動後,另一個敲擊完成。我的iPhone和Android上發生的事情是點擊事件觸發兩次,同時啓動和停止進度條。任何想法,爲什麼發生這種情況,以及如何解決它?注意:我已經試過用vclick替換tap

非常感謝!

回答

5

我最終停止使用 e.stopPropagation()e.preventDefault()

+1

我不工作的情況下傳播 –

0

爲什麼不使用「touchend」事件?

Btw。當您的腳本在運行時被解僱,以確保腳本在運行時無法被解僱時,這是個好主意。如果有人因爲不耐煩而選中它兩次會怎麼樣?

在某些情況下,您可以使用jQuery的函數.one()。在大多數情況下,您需要更大的靈活性,您可以使用簡單的變量檢查來解決問題。