jQuery的插件实现问题 [英] Plugin implementation issue with jQuery

查看:89
本文介绍了jQuery的插件实现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在实现应该是简单"的插件时遇到了问题.插件位于以下地址: http://lab.smashup.it/flip/

I've been having a problem implementing a plugin which is supposed to be "simple". The plugin is at this address : http://lab.smashup.it/flip/

我尝试用一​​个简单的短代码对其进行测试,并检查了显示插件的页面中的代码,以确保我做对了,但是显然什么也没发生,并且我没有收到任何错误反馈,所以我没有不知道该朝哪个方向前进.

I tried testing it out with a simple short code and checked the code from the page where the plugin is displayed to make sure I was doing it right, but apparently nothing happens and I'm not getting any errors feedback so I don't know what direction to go towards.

这是我测试运行的代码:

Here be the code I test ran it with:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Test#0935</title>

        <script src="http://www.google.com/jsapi"></script>
        <script type="text/javascript">
            // Load jQuery 
            google.load("jquery", "1"); 
        </script>
        <script src="JS/jquery-ui-1.7.2.custom.min.js"></script>
        <script src="JS/jquery.flip.min.js"></script>

        <script type="text/javascript">

            $("a").bind("click",function(){
                $("#flipo").flip({
                    direction: "tb"
                })
                return false;
            });

        </script>

        <style type="text/css">

            #flipo {
                width:100px;
                height:70px;
                background-color:lightblue;
                margin:20px;
            }

        </style>

    </head>

    <body>

        <div id="flipo"></div>
        <a href="#" id="left">left</a>

    </body>
</html>

我插入"了与插件作者相同的jQuery库源,并且我已确保对该插件的引用正确.

I "imported" the same source for the jQuery library as the plugin-author did and I've made sure the reference to the plugin is correct.

查看作者页面的源代码,您会发现他也绑定"了链接标签上的click函数,从插件中调用了.flip方法,"tb"的意思是向左翻转".

Looking at the source code for the authors page, you see that he too "binds" a click function on link tags, calls the .flip method from his plugin, and "tb" means "flip leftwards".

推荐答案

$(function() {});包装器包装.bind().这模拟了 $(document).ready() ,这意味着一旦DOM被加载,页面内容被加载,其中的所有内容都将被加载."

Wrap the .bind() in a $(function() {}); wrapper. This simulates $(document).ready(), which means that "everything inside it will load as soon as the DOM is loaded and before the page contents are loaded. "

$(function() {
    $("a").bind("click",function(){
        $("#flipo").flip({
            direction: "tb"
        })
        return false;
    });
});

这篇关于jQuery的插件实现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆