我正在使用jquery ui
tabs
.当使用选项卡时,我遇到了一个场景,在回发期间选项卡没有维护所选索引。我搜索了一下,找到了解决办法。我的问题是隐藏字段中的值在回发期间设置为null,因此在jquery ui
tabs
回发期间无法维护所选索引。
如何解决这个问题?
我的代码
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.1/jquery-ui.js">
<script type="text/javascript">
$(function(){
//maintaining selected tab during postback
var selectedIndex=$("#<%=hFieldTabIndex.ClientID %>").val();
alert(selectedIndex)//here value is always set to null
if(selectedIndex==""){
$("#tabs").tabs({active:0});
}
else{
$("#tabs").tabs({active:1});
}
//Change the text of the button on tab change
$("#tabs").on("tabsactivate",function(){
var index=$("#tabs").tabs("option","active");
$("#<%=hFieldTabIndex.ClientID %>").val(index);//setting the hiddenfield value
alert($("#<%=hFieldTabIndex.ClientID %>").val());//showing currect tab index
if(index=="0"){
$("#btnNext").attr('value','Next>>')
}
else{
$("#btnNext").attr('value','<<Prev')
}
})
您可以使用以下代码
<script type="text/javascript" language="javascript">
$(function() {
$("#example").tabs({
show: function() {
var sel = $('#example').tabs('option', 'selected');
$("#<%= hidLastTab.ClientID %>").val(sel);
},
selected: <%= hidLastTab.Value %>
});
});
如果它不工作,然后尝试使用脚本全局变量,如var tabNo=0;
和设置和获取值相同,你正在使用隐藏字段
终于得到了解决方案,我在页面加载中编写了一些代码来存储hiddenfield的值。
protected void Page_Load(object sender, EventArgs e)
{
hFieldTabIndex.Value = Request.Form[hFieldTabIndex.UniqueID];
}