2012年10月18日 星期四

Jquery-Accordion成長史

1.剛出生只有這樣
// Accordion
$("#accordion").accordion({ header: "h3" });



2.後來希望Postback後他可以不要縮回去
<asp:HiddenField ID="hidAccordionIndex" runat="server" Value="0" />
 <script type="text/javascript">
        $(function () {
var activeIndex = parseInt($('#hidAccordionIndex').val());
            // Accordion
            $("#accordion2").accordion({
                header: "h3",
                autoHeight: false,
                event: "mousedown",
                active: activeIndex,
                change: function (event, ui) {
                    var index = $(this).children('h3').index(ui.newHeader);
                    alert(index);
                    $('#hidAccordionIndex').val(index);
                }
            });
}
</script>

3.之後又希望切換頁面後也不要縮回去...
    // Accordion
    $("#accordion").accordion({
        header: "h3",
        autoHeight: false,
        event: "mousedown",
        active: parseInt($.cookie("AccordionIndex")),
        change: function (event, ui) {
            var index = jQuery(this).find("h3").index(ui.newHeader[0]); //
            $.cookie("AccordionIndex", index);
            //alert(index);              
        }
    });

p.s.需搭配jquery-cookie

--
看到、想到、說到、做到 
能夠填平大海的誓言,也比不上邁出一步的價值 
是以吾輩此生,再無任何誓言

沒有留言: