创建一个用于切换 jQuery 选项卡的“下一步”按钮
如何创建一个滚动到下一个 jQuery 选项卡的按钮。我希望选项卡中有一个下一个按钮,可以滚动到下一个选项卡,有点像分步教程。
这怎么能做到呢?到目前为止我的代码如下。
HTML
<div id="tabs">
<ul>
<li><a href="#fragment-1"><span>One</span></a></li>
<li><a href="#fragment-2"><span>Two</span></a></li>
<li><a href="#fragment-3"><span>Three</span></a></li>
</ul>
<div id="fragment-1">
<p>First tab is active by default:</p> <a href="nexttab">Next Tab</a>
</div>
<div id="fragment-2">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh</div>
<div id="fragment-3">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh</div>
</div>
JS
$(document).ready(function () {
$("#tabs").tabs();
});
How can I create a button that will scroll to the next jQuery tab. I want to have a next button within the tabs that will scroll to the next tab, sort of like a step-by-step tutorial.
How can this be done? My code so far is below.
HTML
<div id="tabs">
<ul>
<li><a href="#fragment-1"><span>One</span></a></li>
<li><a href="#fragment-2"><span>Two</span></a></li>
<li><a href="#fragment-3"><span>Three</span></a></li>
</ul>
<div id="fragment-1">
<p>First tab is active by default:</p> <a href="nexttab">Next Tab</a>
</div>
<div id="fragment-2">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh</div>
<div id="fragment-3">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh</div>
</div>
JS
$(document).ready(function () {
$("#tabs").tabs();
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
selected
选项 来移动,例如this:只需更改您的锚点即可匹配,如下所示:
您可以在此处查看演示
或者,将每个“下一步” Tab”链接指向特定选项卡并使用
select
方法,像这样:然后你可以使用更短的 jQuery,并移动到你想要的任何选项卡:
这是一个演示这种方法的
You can use the
selected
option to move around, like this:Just change your anchor to match, like this:
You can view a demo here
Alternatively, make each "Next Tab" link point to a specific tab and use the
select
method, like this:Then you can use a bit shorter jQuery, and move to any tab you want:
Here's a demo of this approach
我发现在 UI 1.10.0 中这个解决方案不再有效,因为“selected”已被弃用。以下内容适用于 1.10 及更早版本 -
I found that with UI 1.10.0 this solution no longer works, as "selected" was deprecated. The following will work in both 1.10 and earlier versions-
根据 Nick Craver 的回答,以下是我如何使用下一个按钮生成相同的功能,这些按钮在每个选项卡 div 底部的 HTML 中看起来像这样:
根据 Nick 的回答,我创建了两个函数:
由于每个按钮都属于“btnNext”类,页面加载后,我调用:
这使得每个按钮都能够移动到下一个选项卡。
Based on Nick Craver's answer, here's how I produced the same functionality using next-buttons that look like this in the HTML at the bottom within each tab div:
Based on Nick's answer I created two functions:
Since each button belongs to the "btnNext" class, after the page loads, I call:
and this enables each button's ability to move to the next tab.