jQuery+Edge Animate:仅当从单击事件调用时才出错:对象 [对象对象] 没有方法'foundation'



使用Zurb Foundation和jQuery与Edge Animate,我得到这个错误:

未捕获的类型错误:对象 [对象对象] 没有方法"基础"

....仅当从事件处理程序中调用 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 内容存在时,才会发生此错误。删除后,它按预期工作。

我没有意识到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>

最新更新