我试图弄清楚如何在回发期间保持当前的手风琴窗格打开。我查看了这些帖子,但他们都使用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>
答案 0 :(得分:0)
使用隐藏字段存储索引介于回发之间
<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>