简体   繁体   English

如何使手风琴标题最初在页面加载时折叠?

[英]how to make accordion headers all collapsed initially on page load?

I added this script on my page..it didnt work

    <script type="text/javascript">
    $(document).ready(function(){
      $("#accordion").accordion( { active: false, collapsible: true });
    });

my accordion 我的手风琴

<cc1:Accordion ID="Accordion1" runat="server" FadeTransitions="true"  Visible="true" AutoSize="None"SelectedIndex="0" RequireOpenedPane="false"  TransitionDuration="250" 
HeaderCssClass="accordionHeader toggler" ContentCssClass="accordionContent expanded toggler">
                <HeaderTemplate>

                    <b style="color: Black">

                        <%#Eval("Ques")%>
                    </b>

                </HeaderTemplate>


                <ContentTemplate>
                <p> <%#DataBinder.Eval(Container.DataItem, "QuesAns")%></p>

                </ContentTemplate>
            </cc1:Accordion>

I see the first header expanded when page's loaded. 我看到第一个页面在页面加载时展开了。 How to make them all collapsed on page load? 如何让它们在页面加载时全部折叠?

有一个简单的解决方法 - 只需设置SelectedIndex="-1"而不是“0”(加上RequireOpenedPane =“false”,但它已经在你的标记中设置)..你真的不需要那个花哨的onReady脚本。

I think your selector is wrong. 我认为你的选择器是错误的。

Try 尝试

$(document).ready(function(){
   $("#<%=Accordion1.ClientID %>").accordion( { active: false, collapsible: true });
});

You have to set 你必须设置

Accordion1.RequireOpenedPane = false;

To have them all closed. 让它们全部关闭。 And possible set selectedIndex to -1 并且可以将selectedIndex设置为-1

I think your selector is wrong: 我认为你的选择器错了:

$(document).ready(function(){
   $("#<%= Accordion1.ClientID %>").accordion( { active: false, collapsible: true });
});

This would have to go inside your page, not in an external javascript file or the <%= %> code block wont get executed. 这必须进入你的页面,而不是在外部javascript文件或<%=%>代码块不会被执行。

Side note: You are using jquery notation which looks like the jquery UI accordion code but then trying to apply it to what looks like the asp.net Ajax Control Toolkit accordion control. 旁注:您正在使用jquery表示法,它看起来像jquery UI手风琴代码,但后来尝试将其应用于看起来像asp.net Ajax Control Toolkit手风琴控件。 If this is what you are doing then it probably wont work. 如果这是你正在做的事情那么它可能不会工作。 However if you have the very latest version of ACT included with the Microsoft Ajax library then you could be correct here. 但是,如果您在Microsoft Ajax库中包含最新版本的ACT,那么您可能在这里是正确的。 I know that they have reimplemented all of the ACT controls to be exposed as jquery plugins but I havent used that release. 我知道他们已经重新实现了所有ACT控件作为jquery插件公开但我没有使用该版本。

On a sidenote: When using accordion (or other js-triggered layout), you will be risking FOUC (Flash Of Unstyled Content). 旁注:当使用手风琴(或其他js触发的布局)时,您将冒着FOUC(Flash Of Unstyled Content)的风险。 I would wrap the accordion control in a div, with display:none in your css and when the accordion javascript is executed, you use JQuerys show() to make it visible again. 我将把手风琴控件包装在div中,在你的css中使用display:none,并且当执行手风琴javascript时,你使用JQuerys show()使它再次可见。 Then the accordion will be loaded and styled before it's shown. 然后手风琴将在显示之前加载并设置样式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM