문제 설명
양식 제출 후 현재 탭 유지 (Keeping the current tabs after submitting the form)
I know this question was asked before by many people but I didn't get the solution and i'm not really good in Jquery so, what i did is that i implemented tabs in my page and eache one has a form but when i click on the button of the second the page give me the first tab after reloading. This is my Code jquery :
<script type="text/javascript">
$(document).ready( function() {
$('#tab‑container').easytabs();
});
</script>
What I have is exactlly what is in this page demo :http://jspkg.com/packages/easytabs/demos
How can i resolve the problem ?
참조 솔루션
방법 1:
Either improve your HTML/ HTTP post structure:
- Set a hidden field in your FORM, to specify which tab is selected.
- Use the resulting request parameter server‑side, to
- Select the correct tab to show in the round‑tripped result page.
(If you have one FORM for the whole page, you can set the value of that on the tab select
event.. if you have one form per tab, it's just a constant.)
$('#tab‑container').easytabs(
defaultTab: '${defaultTab_Selector}'
);
If you're using MVC and JSP, you'd set "defaultTab_Selector" to be a selector to find the <li>
of the tab. (I use jQuery UI Tabs, which just uses a numeric index to do this bit.)
In Spring MVC, if your second tab is <li id='tab2'>
:
ModelAndView mv = new ModelAndView("gestion_user");
mv.addObject( "defaultTab_Selector", "#tab2");
return mv;
Or post by AJAX.
방법 2:
Try this:
$('#tab‑container').easyTabs({ updateHash: false });
(by Souad、Thomas W、user3652092)