【问题标题】:zepto js - simple toggle not workingzepto js - 简单的切换不起作用
【发布时间】:2012-04-16 04:40:59
【问题描述】:

我在移动网站上使用 zepto (http://zeptojs.com/)(我习惯在桌面环境中使用 jQuery)。

我有以下代码(稍作调整以便在桌面上运行)

(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 不是函数 源文件:file:/js/zepto.min.js 行:1

【问题讨论】:

    标签: jquery zepto


    【解决方案1】:

    你基本上是对的。您混淆了函数参数的顺序。 delegate 函数已被弃用,因此您也应该使用 on

    替换这个:

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

    用这个:

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

    【讨论】:

      猜你喜欢
      • 2018-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-30
      • 1970-01-01
      相关资源
      最近更新 更多