2012-04-02 120 views
0

我正在使用zepto(http://zeptojs.com/)爲移動網站(我習慣在桌面環境中使用jQuery)。zepto js - 簡單切換不起作用

我有以下代碼(略有調整,這樣它適用於臺式機)

(function($) { 
    // only do this if not on a touch device 
    if (!('ontouchend' in window)) { 
     $(document).delegate('.filter h2', 'click', function(e) { 
      $('.filter div').toggle(); 
      e.preventDefault(); 
     }); 
    } 
})(window.Zepto); 

然而撥動心不是工作。如果我用標準alert('hello world');替換那條線,它會被拾取(所以我知道js被調用)。

任何想法我失蹤?

乾杯, 廣告。

編輯 我似乎得到這個錯誤: 時間戳:02/04/2012 15時02分35秒 錯誤:h.body.insertAdjacentElement不是一個函數 源文件:文件:/ JS /仄。 min.js Line:1

+0

看起來像一個Firefox的問題 – Adi 2012-04-02 14:27:10

回答

1

你已經明白了。你混淆了函數參數的順序。 delegate函數已棄用,因此您也應該使用on

替換此:

$(document).delegate('.filter h2', 'click', function(e) { 

與此:

$(document).on('click', '.filter h2', function(e) {