Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何仅使用样式在回发时保持当前手风琴打开?_Jquery_Css_Accordion - Fatal编程技术网

Jquery 如何仅使用样式在回发时保持当前手风琴打开?

Jquery 如何仅使用样式在回发时保持当前手风琴打开?,jquery,css,accordion,Jquery,Css,Accordion,我正在试图找出如何在回发期间保持当前手风琴窗格打开。我已经浏览了这些帖子,但它们都在jQuery中使用实际的手风琴功能,而我只使用css <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Editor.aspx.vb" Inherits="Editor" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3

我正在试图找出如何在回发期间保持当前手风琴窗格打开。我已经浏览了这些帖子,但它们都在jQuery中使用实际的手风琴功能,而我只使用css

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Editor.aspx.vb" Inherits="Editor" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>MLE Editor</title>
    <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>

    <link href="Styles/site.css" rel="stylesheet" type="text/css" />    

<script type="text/javascript">
    $(document).ready(function () {
        // The Accordion Effect
        $('.eventHeader').click(function () {
            $(this).toggleClass('active-header').toggleClass('inactive-header');
            $(this).next().slideToggle().toggleClass('open-content');
        });
    });
</script>
</head>
<body>
    <form id="form1" runat="server">        
        <div id="eventOptions">
            <div id="eventsContainer"> 
                <h2 class="eventHeader">Event 1</h2><div class="eventContent"><p>Event options</p></div>
                <h2 class="eventHeader">Event 2</h2><div class="eventContent"><p>Event options</p></div>
                <h2 class="eventHeader">Event 3</h2><div class="eventContent"><p>Event options</p></div>
                <h2 class="eventHeader">Event 4</h2><div class="eventContent"><p>Event options</p></div>
                <h2 class="eventHeader">Event 5</h2><div class="eventContent"><p>Event options</p></div>
            </div>
        </div>
        <asp:Button ID="btnPostback" Runat="server" Text="Postback" />
    </form>
</body>
</html>

MLE编辑器
$(文档).ready(函数(){
//手风琴效果
$('.eventHeader')。单击(函数(){
$(this).toggleClass('active-header')。toggleClass('inactive-header');
$(this).next().slideToggle().toggleClass('open-content');
});
});
事件1事件选项

事件2事件选项

事件3事件选项

事件4事件选项

事件5事件选项


使用隐藏字段在回发之间存储索引Id

<asp:HiddenField runat="server" ID="hdnIndexValue1" Value="-1" />

<script type="text/javascript">
    $(document).ready(function () {
        $(".eventContent").hide();
        var index = parseInt(document.getElementById("hdnIndexValue1").value);
        $('.eventContent:eq(' + index + ')').show();

        $('.eventHeader').click(function () {
            $(this).toggleClass('active-header').toggleClass('inactive-header');
            $(this).next().slideToggle().toggleClass('open-content');
            var index = $(".eventHeader").index(this);
            document.getElementById('hdnIndexValue1').value = index;
        });
    });
</script>

$(文档).ready(函数(){
$(“.eventContent”).hide();
var index=parseInt(document.getElementById(“hdnIndexValue1”).value);
$('.eventContent:eq('+index+')).show();
$('.eventHeader')。单击(函数(){
$(this).toggleClass('active-header')。toggleClass('inactive-header');
$(this).next().slideToggle().toggleClass('open-content');
var index=$(“.eventHeader”).index(此);
document.getElementById('hdnIndexValue1')。值=索引;
});
});

您回邮的目的是什么?如果要重新加载页面,则需要添加以前打开过的类,否则可以使用更新面板,以便只重新加载页面的已处理部分。这只是原始文件的简化版本。因此,我的回帖只是在屏幕上写出当前的日期时间。我会用一个更新面板来显示日期时间写入屏幕的位置,这在我上面的简短示例中对我有所帮助,但并没有回答如何使用javascript来实现这一点的实际问题。上面的版本被简化了,我试图这样做,这样我就不必发布整个2000行的aspx文件。您需要做的是查看ajax回发或更新面板,以了解它们是如何工作的。如果您进行回发,它将重新加载您的页面,这意味着客户端发生的任何事情都将丢失(即任何手风琴点击和jquery类的更改),或者您可以设置cookie(我建议不要这样做)当您单击面板时,它会告诉您哪个面板处于打开状态,然后当页面重新加载时,您可以使用此cookie重新打开正确的面板