jQuery + Edge Animate:仅在从click事件调用时出错:Object [object Object]没有方法'foundation'

时间:2013-09-06 22:44:15

标签: javascript jquery zurb-foundation adobe-edge

使用Zurb Foundation和jQuery with Edge Animate我收到此错误:

  

未捕获的TypeError:对象[object Object]没有方法'foundation'

....仅在从事件处理程序中调用基础函数时。从事件处理程序外部,它工作正常。

<div id="myModal" class="reveal-modal">
    <h2>Title</h2>
    <p class="lead">Description</p>
    <a class="close-reveal-modal">&#215;</a>
</div>
<a href="#" id="myButton" class="button">Click Me</a>

<script>
    $(document).foundation();

    // This works as expected
    $('#myModal').foundation('reveal', 'open');

    $("#myButton").click(function() {

        // This generates the error:
        // Uncaught TypeError: Object [object Object] has no method 'foundation'

        $('#myModal').foundation('reveal', 'open');

        return false;
    });


</script>

我该如何解决这个问题?只有Edge Animate内容存在时才会出现该错误。删除后,它按预期工作。

1 个答案:

答案 0 :(得分:0)

我没有意识到Edge在jQuery版本中加载。使用jQuery的noConflict()修复了问题:

<script>
    $(document).foundation();

    $.noConflict();
    jQuery(document).ready(function($) {
        // Code that uses jQuery's $ can follow here.

        // This works as expected
        $('#myModal').foundation('reveal', 'open');

        $("#myButton").click(function() {
            // This generates the error:
            //Uncaught TypeError: Object [object Object] has no method 'foundation'

            $('#myModal').foundation('reveal', 'open');
            return false;
        })

    });
</script>