我在asp.net mvc应用程序中有jquery手风琴,我试图在回发后保持当前窗格打开。我尝试了这个Keep the current jQuery accordion pane open after ASP.NET postback?下提供的解决方案。但是,对我来说似乎没有用。
<input type="hidden" id="hidAccordionIndex" value="0" />
<script>
$(function () {
var activeIndex = document.getElementById("hidAccordionIndex").value;
$("#accordion").accordion({
heightStyle: "content",
collapsible: true,
navigation: true,
active: activeIndex,
change: function (event, ui) {
var index = $(this).accordion("option", "active");
$(document.getElementById("hidAccordionIndex")).val(index);
}
});
} );
</script>
答案 0 :(得分:0)
你的语法不正确:
$(document.getElementById("hidAccordionIndex")).val(index);
document.getElementById("hidAccordionIndex")
返回相应HTML元素的原始id值(并且没有id
选择器来定义目标元素的id
属性),因此您需要使用jQuery id selector设置其值:
$("#hidAccordionIndex").val(index);
或者使用vanilla JS版本:
document.getElementById("hidAccordionIndex").value = index;
答案 1 :(得分:0)
<input type="hidden" id="hidAccordionIndex" value="0" />
<script>
$(function () {
var activeIndex = parseInt($("#hidAccordionIndex").val());
console.log(activeIndex);
$("#accordion").accordion({
heightStyle: "content",
collapsible: true,
navigation: true,
active: activeIndex,
activate: function (event, ui) {
var index = $(this).accordion("option", "active");
console.log(index);
$("#hidAccordionIndex").val(index);
}
});
} );
</script>