是否可以在后面的代码中将手风琴的SelectedIndex设置为用户只需单击的相同索引?
答案 0 :(得分:0)
Accordion.SelectedIndex = -1;
Accordion.RequireOpenedPane = false;
答案 1 :(得分:0)
我的解决方案:
在页面顶部,使用手风琴控件ID Accordion1:
<script type="text/javascript" language="javascript">
function createCookie(name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
} else var expires = "";
document.cookie = escape(name) + "=" + escape(value) + expires + "; path=/";
}
function readCookie(name) {
var nameEQ = escape(name) + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length, c.length));
}
return null;
}
function pageLoad() {
var current_path = window.location.pathname.split('/').pop();
console.log('current path:'+current_path);
$find('Accordion1_AccordionExtender').add_selectedIndexChanged(onAccordionPaneChanged);
var idx = readCookie('a_index');
changeSelected(idx);
$find('Accordion1_AccordionExtender').set_TransitionDuration(50);
}
// expand given accordion pane
function changeSelected(idx) {
$find('Accordion1_AccordionExtender').set_SelectedIndex(idx);
}
function onAccordionPaneChanged(sender, eventArgs) {
var selPane = sender.get_SelectedIndex();
// alert('You selected Pane ' + selPane);
createCookie('a_index', selPane, 1);
}
</script>
在背后的代码中:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim si As String = String.Empty 'selected index
If Request.Cookies("a_index") IsNot Nothing Then
si = Request.Cookies("a_index").Value
If si <> String.Empty Then
Accordion1.SelectedIndex = si
End If
End If
End Sub