生活在远方

是的,因为真正的生活是在远方

【jQuery】示例6:可以伸展的面板

Written By: tr - Dec• 28•08

是的,这个是示例6,而不是计划中的示例5(投票系统)。因为在jQuery中,进行可以伸展的面板的处理非常简单,只要一个toggle()函数就可以。

核心代码如下:

var i=0;
$(document).ready(
    function()
    {
        $("div").filter("#clickme").click(
            function()
            {
                i++;
                $("div").filter("#content").toggle();
                if(i%2==0)
                {
                    $(this).text("Click here to expand.");
                }
                else
                {
                    $(this).text("Click here to collapse.");
                }
            }
        );
    }
);

我用了一个变量i来判断要操作的div是处在显示还是隐藏状态,并相应的修改提示文字。通过查看jQuery的源代码,可以知道这也是jQuery中toggle使用的方法。

示例见此处

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">