jQuery:上一个/下一个选项卡链接不起作用!
我添加了按钮,并将上一个和下一个链接的 href 设置为列表项中的 href。当我单击上一个或下一个时,链接在浏览器中看起来正确,但它们会转到同一页面而不是指定的选项卡。
我有十几个带有选项卡的表单,每个表单都有不同数量的选项卡。这些选项卡是静态的(不是用 AJAX 拉入的),我真的很想动态设置它们的 href,而不是像下面那样布置每个选项卡。 (每个选项卡都有一个以 subform 开头的 id。
我查看了这个 关于使用选项卡插件进行选择的对话,但不确定如何将其应用到我的情况。我对 jQuery 真的很陌生!我知道的越多,我想做的就越多似乎我知道的更少!我很感激任何
建议
<ul class="tabNavigation">
<li class="tabs-selected">
<a href="#tab_1">Organization</a></li>
<li><a href="#tab_2">Leaders</a> </li>
<li><input type="submit" name="submit" value=" Save " /></li>
</ul>
<!-- tab containers -->
<div class="tabs-container" id="tab_1">
<div class="subform" id="subform1">
<? include_once ('org.php'); ?>
</div>
</div>
<div class="tabs-container" id="tab_2">
<div class="subform" id="subform2">
<? include_once ('event.php'); ?>
</div>
</div>
!
$(document).ready(function() {
//add previous/next buttons to bottom of each subform
$(".subform").append('<div id="nav_buttons"><p><a href="" class="previous floatleft">Previous</a> <a href="" class="next floatright">Next</a></p></div>');
$("#subform1 .previous").hide(); //hide previous button on tab_1
$("#subform1 a.next").attr("href","#tab_2");
$("#subform2 a.previous").attr("href","#tab_1");
$("#subform2 .next").hide(); //hide next button on last tab
});
I added the buttons and set the hrefs for previous and next links to the hrefs from the list items. The links look right in the browser when I click on previous or next, but they go to the same page instead of the specified tab.
I have a dozen of these forms with the tabs and each form has a different number of tabs. The tabs are static (not pulled in with AJAX), and I'd really like to set their hrefs dynamically instead of laying out each one the way I did below. (Each tab has an id that begins with subform.
I looked at this conversation on select with the tabs plugin but wasn't sure how to apply it to my situation. I'm really new at jQuery! The more I know, the more I want to do and it seems like the less I know! I'd appreciate any advice!!
HTML:
<ul class="tabNavigation">
<li class="tabs-selected">
<a href="#tab_1">Organization</a></li>
<li><a href="#tab_2">Leaders</a> </li>
<li><input type="submit" name="submit" value=" Save " /></li>
</ul>
<!-- tab containers -->
<div class="tabs-container" id="tab_1">
<div class="subform" id="subform1">
<? include_once ('org.php'); ?>
</div>
</div>
<div class="tabs-container" id="tab_2">
<div class="subform" id="subform2">
<? include_once ('event.php'); ?>
</div>
</div>
jQuery:
$(document).ready(function() {
//add previous/next buttons to bottom of each subform
$(".subform").append('<div id="nav_buttons"><p><a href="" class="previous floatleft">Previous</a> <a href="" class="next floatright">Next</a></p></div>');
$("#subform1 .previous").hide(); //hide previous button on tab_1
$("#subform1 a.next").attr("href","#tab_2");
$("#subform2 a.previous").attr("href","#tab_1");
$("#subform2 .next").hide(); //hide next button on last tab
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你可以利用所选的属性:
I think you can make use of the selected attribute:
我在 Cris Coyier 的网站 CSS-Tricks 上找到了答案。文章 带有下一个/上一个的 jQuery UI 选项卡
这里是有效的代码:
它最酷的地方在于它找到 div 的数量(为每个选项卡提供内容),然后以编程方式附加下一个/上一个按钮,跳过第一个上一个按钮和最后一个下一个按钮。
效果很好!
I found the answer on Cris Coyier's site, CSS-Tricks. The article, jQuery UI Tabs with Next/Previous
Here is the code that worked:
What's cool about it is that it finds the number of divs (that provide content for each tab) and then appends the next/previous buttons programmatically, skipping the first previous button and the last next button.
Works great!