我正在尝试通过选项卡获取下一个按钮。任何帮助赞赏。 html位于Codepen snippet。
提前致谢。
function tabsResponsive() {
$('.accordion-tabs').each(function(index) {
$(this).children('li').first().children('a').addClass('is-active').next().addClass('is-open').show();
});
$('.accordion-tabs').on('click', 'li > a.tab-link', function(event) {
if (!$(this).hasClass('is-active')) {
event.preventDefault();
var accordionTabs = $(this).closest('.accordion-tabs');
accordionTabs.find('.is-open').removeClass('is-open').hide();
$(this).next().toggleClass('is-open').toggle();
accordionTabs.find('.is-active').removeClass('is-active');
$(this).addClass('is-active');
} else {
event.preventDefault();
}
});
}
function tabsNext() {
$('.nextContaner__link').click(function() {
$('.tab-link').each(function(index) {
if ($(this).hasClass('is-active')) {
$(this).removeClass('is-active');
$(this).parent().siblings('li').next('').children('a').addClass('is-active');
} else {
event.preventDefault();
}
// $(this).removeClass('is-active');
// $(this).parent().siblings('li').next().children('a').addClass('is-active');
});
});
}
答案 0 :(得分:1)
您可以像这样更改您的功能:
function tabsNext() {
$('.nextContaner__link').click(function() {
var elem = $(".tab-link.is-active").closest(".tab-header-and-content").next(".tab-header-and-content");
if(elem.length > 0){
elem.find("a").trigger("click");
}else{
$(".tab-header-and-content").eq(0).find("a").trigger("click");
}
});
}
更新笔: https://codepen.io/anon/pen/xrwygz
虽然我使用了触发器("单击"),但您可以使用添加/删除类的常规方法。
答案 1 :(得分:1)
简单,不使用链接上的课程,您只需检查有效标签,然后将下一个标签的链接设置为有效并从之前删除,
你的功能应该是
function tabsNext() {
$('.nextContaner__link').click(function() {
var $tab = $(".is-active.tab-link");
console.log()
if ($tab.parent().next().hasClass("tab-header-and-content")) {
$tab.parent().find(".tab-content").hide();
$tab.parent().next().find("a").addClass("is-active");
$tab.parent().next().find(".tab-content").show();
$tab.removeClass("is-active")
}else {
$tab.parent().find(".tab-content").hide();
$tab.removeClass("is-active");
$(".tab-header-and-content").eq(0).find(".tab-link").addClass("is-active");
$(".tab-header-and-content .tab-content").eq(0).show();
}
});
}
请注意一个片段,请全屏幕执行:
function tabsResponsive() {
$('.accordion-tabs').each(function(index) {
$(this).children('li').first().children('a').addClass('is-active').next().addClass('is-open').show();
});
$('.accordion-tabs').on('click', 'li > a.tab-link', function(event) {
if (!$(this).hasClass('is-active')) {
event.preventDefault();
var accordionTabs = $(this).closest('.accordion-tabs');
accordionTabs.find('.is-open').removeClass('is-open').hide();
$(this).next().toggleClass('is-open').toggle();
accordionTabs.find('.is-active').removeClass('is-active');
$(this).addClass('is-active');
} else {
event.preventDefault();
}
});
}
function tabsNext() {
$('.nextContaner__link').click(function() {
var $tab = $(".is-active.tab-link");
if ($tab.parent().next().hasClass("tab-header-and-content")) {
$tab.parent().find(".tab-content").hide();
$tab.parent().next().find("a").addClass("is-active");
$tab.parent().next().find(".tab-content").show();
$tab.removeClass("is-active")
}else {
$tab.parent().find(".tab-content").hide();
$tab.removeClass("is-active");
$(".tab-header-and-content").eq(0).find(".tab-link").addClass("is-active");
$(".tab-header-and-content .tab-content").eq(0).show();
}
});
}
//--------------------------------------------------------------------------------------------------------------
// DOCUMENT READY
$(function() {
tabsResponsive();
tabsNext();
}); // END DOCUMENT READY
//--------------------------------------------------------------------------------------------------------------
// WINDOW LOAD
$(window).load(function() {
w = $(window).width();
}); // END WINDOW LOAD
//--------------------------------------------------------------------------------------------------------------
// WINDOW RESIZE
// var resizeTimer;
// $(window).on('resize orientationchange', function() {
//
// if( w !== $( window ).width() ){
//
// clearTimeout(resizeTimer);
//
// //stuff that gets delayed
// resizeTimer = setTimeout(function() {
//
//
// }, 600);
//
//
// w = $( window ).width();
// }
// }); // END WINDOW RESIZE

.accordion-tabs {
margin-top:40px;
}
html {
line-height: 1.15;
/* 1 */
-ms-text-size-adjust: 100%;
/* 2 */
-webkit-text-size-adjust: 100%;
/* 2 */
}
/* Sections
========================================================================== */
/**
* Remove the margin in all browsers (opinionated).
*/
body {
margin: 0;
}
/**
* Add the correct display in IE 9-.
*/
article,
aside,
footer,
header,
nav,
section {
display: block;
}
/**
* Correct the font size and margin on `h1` elements within `section` and
* `article` contexts in Chrome, Firefox, and Safari.
*/
h1 {
font-size: 2em;
margin: 0.67em 0;
}
/* Grouping content
========================================================================== */
/**
* Add the correct display in IE 9-.
*/
figcaption,
figure {
display: block;
}
/**
* Add the correct margin in IE 8.
*/
figure {
margin: 1em 40px;
}
/**
* 1. Add the correct box sizing in Firefox.
* 2. Show the overflow in Edge and IE.
*/
hr {
box-sizing: content-box;
/* 1 */
height: 0;
/* 1 */
overflow: visible;
/* 2 */
}
/**
* Add the correct display in IE.
*/
main {
display: block;
}
/**
* 1. Correct the inheritance and scaling of font size in all browsers.
* 2. Correct the odd `em` font sizing in all browsers.
*/
pre {
font-family: monospace, monospace;
/* 1 */
font-size: 1em;
/* 2 */
}
/* Links
========================================================================== */
/**
* 1. Remove the gray background on active links in IE 10.
* 2. Remove gaps in links underline in iOS 8+ and Safari 8+.
*/
a {
background-color: transparent;
/* 1 */
-webkit-text-decoration-skip: objects;
/* 2 */
}
/* Text-level semantics
========================================================================== */
/**
* 1. Remove the bottom border in Chrome 57- and Firefox 39-.
* 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.
*/
abbr[title] {
border-bottom: none;
/* 1 */
text-decoration: underline;
/* 2 */
text-decoration: underline dotted;
/* 2 */
}
/**
* Prevent the duplicate application of `bolder` by the next rule in Safari 6.
*/
b,
strong {
font-weight: inherit;
}
/**
* Add the correct font weight in Chrome, Edge, and Safari.
*/
b,
strong {
font-weight: bolder;
}
/**
* 1. Correct the inheritance and scaling of font size in all browsers.
* 2. Correct the odd `em` font sizing in all browsers.
*/
code,
kbd,
samp {
font-family: monospace, monospace;
/* 1 */
font-size: 1em;
/* 2 */
}
/**
* Add the correct font style in Android 4.3-.
*/
dfn {
font-style: italic;
}
/**
* Add the correct background and color in IE 9-.
*/
mark {
background-color: #ff0;
color: #000;
}
/**
* Add the correct font size in all browsers.
*/
small {
font-size: 80%;
}
/**
* Prevent `sub` and `sup` elements from affecting the line height in
* all browsers.
*/
sub,
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline;
}
sub {
bottom: -0.25em;
}
sup {
top: -0.5em;
}
/* Embedded content
========================================================================== */
/**
* Add the correct display in IE 9-.
*/
audio,
video {
display: inline-block;
}
/**
* Add the correct display in iOS 4-7.
*/
audio:not([controls]) {
display: none;
height: 0;
}
/**
* Remove the border on images inside links in IE 10-.
*/
img {
border-style: none;
}
/**
* Hide the overflow in IE.
*/
svg:not(:root) {
overflow: hidden;
}
/* Forms
========================================================================== */
/**
* 1. Change the font styles in all browsers (opinionated).
* 2. Remove the margin in Firefox and Safari.
*/
button,
input,
optgroup,
select,
textarea {
font-family: sans-serif;
/* 1 */
font-size: 100%;
/* 1 */
line-height: 1.15;
/* 1 */
margin: 0;
/* 2 */
}
/**
* Show the overflow in IE.
*/
button {
overflow: visible;
}
/**
* Remove the inheritance of text transform in Edge, Firefox, and IE.
* 1. Remove the inheritance of text transform in Firefox.
*/
button,
select {
/* 1 */
text-transform: none;
}
/**
* 1. Prevent a WebKit bug where (2) destroys native `audio` and `video`
* controls in Android 4.
* 2. Correct the inability to style clickable types in iOS and Safari.
*/
button,
html [type="button"],
[type="reset"],
[type="submit"] {
-webkit-appearance: button;
/* 2 */
}
button,
[type="button"],
[type="reset"],
[type="submit"] {
/**
* Remove the inner border and padding in Firefox.
*/
/**
* Restore the focus styles unset by the previous rule.
*/
}
button::-moz-focus-inner,
[type="button"]::-moz-focus-inner,
[type="reset"]::-moz-focus-inner,
[type="submit"]::-moz-focus-inner {
border-style: none;
padding: 0;
}
button:-moz-focusring,
[type="button"]:-moz-focusring,
[type="reset"]:-moz-focusring,
[type="submit"]:-moz-focusring {
outline: 1px dotted ButtonText;
}
/**
* Show the overflow in Edge.
*/
input {
overflow: visible;
}
/**
* 1. Add the correct box sizing in IE 10-.
* 2. Remove the padding in IE 10-.
*/
[type="checkbox"],
[type="radio"] {
box-sizing: border-box;
/* 1 */
padding: 0;
/* 2 */
}
/**
* Correct the cursor style of increment and decrement buttons in Chrome.
*/
[type="number"]::-webkit-inner-spin-button,
[type="number"]::-webkit-outer-spin-button {
height: auto;
}
/**
* 1. Correct the odd appearance in Chrome and Safari.
* 2. Correct the outline style in Safari.
*/
[type="search"] {
-webkit-appearance: textfield;
/* 1 */
outline-offset: -2px;
/* 2 */
/**
* Remove the inner padding and cancel buttons in Chrome and Safari on macOS.
*/
}
[type="search"]::-webkit-search-cancel-button,
[type="search"]::-webkit-search-decoration {
-webkit-appearance: none;
}
/**
* 1. Correct the inability to style clickable types in iOS and Safari.
* 2. Change font properties to `inherit` in Safari.
*/
::-webkit-file-upload-button {
-webkit-appearance: button;
/* 1 */
font: inherit;
/* 2 */
}
/**
* Correct the padding in Firefox.
*/
fieldset {
padding: 0.35em 0.75em 0.625em;
}
/**
* 1. Correct the text wrapping in Edge and IE.
* 2. Correct the color inheritance from `fieldset` elements in IE.
* 3. Remove the padding so developers are not caught out when they zero out
* `fieldset` elements in all browsers.
*/
legend {
box-sizing: border-box;
/* 1 */
display: table;
/* 1 */
max-width: 100%;
/* 1 */
padding: 0;
/* 3 */
color: inherit;
/* 2 */
white-space: normal;
/* 1 */
}
/**
* 1. Add the correct display in IE 9-.
* 2. Add the correct vertical alignment in Chrome, Firefox, and Opera.
*/
progress {
display: inline-block;
/* 1 */
vertical-align: baseline;
/* 2 */
}
/**
* Remove the default vertical scrollbar in IE.
*/
textarea {
overflow: auto;
}
/* Interactive
========================================================================== */
/*
* Add the correct display in Edge, IE, and Firefox.
*/
details {
display: block;
}
/*
* Add the correct display in all browsers.
*/
summary {
display: list-item;
}
/*
* Add the correct display in IE 9-.
*/
menu {
display: block;
}
/* Scripting
========================================================================== */
/**
* Add the correct display in IE 9-.
*/
canvas {
display: inline-block;
}
/**
* Add the correct display in IE.
*/
template {
display: none;
}
/* Hidden
========================================================================== */
/**
* Add the correct display in IE 10-.
*/
[hidden] {
display: none;
}
/* -------------------------------------------------------------
Sass CSS3 Mixins! The Cross-Browser CSS3 Sass Library
By: Matthieu Aussaguel, http://www.mynameismatthieu.com, @matthieu_tweets
List of CSS3 Sass Mixins File to be @imported and @included as you need
The purpose of this library is to facilitate the use of CSS3 on different browsers avoiding HARD TO READ and NEVER
ENDING css files
note: All CSS3 Properties are being supported by Safari 5
more info: http://www.findmebyip.com/litmus/#css3-properties
------------------------------------------------------------- */
.wrap {
max-width: 1600px;
margin-left: auto;
margin-right: auto;
padding: 0 10px;
}
.wrap:after {
content: " ";
display: block;
clear: both;
}
.accordion-tabs {
line-height: 1.5;
margin-bottom: 1.5em;
padding: 0;
width: 100%;
}
.accordion-tabs::after {
clear: both;
content: "";
display: block;
}
.accordion-tabs .tab-header-and-content {
list-style: none;
}
@media (min-width: 40em) {
.accordion-tabs .tab-header-and-content {
display: inline;
}
}
@media (min-width: 40em) {
.accordion-tabs .tab-header-and-content:first-child .tab-link {
border-top: 0;
}
}
.accordion-tabs .tab-link {
background-color: #fff;
color: #333;
display: block;
font-weight: bold;
padding: 0.75em 0;
text-decoration: none;
}
@media (min-width: 40em) {
.accordion-tabs .tab-link {
border-left: 0;
border-right: 0;
border-top: 0;
display: inline-block;
width: 23%;
text-align: center;
}
}
.accordion-tabs .tab-link:hover {
color: #477dca;
}
.accordion-tabs .tab-link:focus {
outline: none;
}
.accordion-tabs .tab-link.is-active {
background-color: #fff;
color: #0a79bc;
}
@media (min-width: 40em) {
.accordion-tabs .tab-link.is-active {
background-color: #fff;
border-bottom: 2px solid #0a79bc;
margin-bottom: -1px;
}
}
.accordion-tabs .tab-content {
background: #fff;
display: none;
padding: 1.5em 1.5em;
}
@media (min-width: 40em) {
.accordion-tabs .tab-content {
float: left;
}
}
.accordion-tabs .nextContainer {
list-style: none;
display: block;
width: 100%;
clear: both;
}
.accordion-tabs .nextContaner__link {
padding: 20px;
display: block;
float: right;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="accordion-tabs">
<li class="tab-header-and-content">
<a href="javascript:void(0)" class="is-active tab-link">Tab Item</a>
<div class="tab-content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras tincidunt pellentesque lorem, id suscipit dolor rutrum id. Morbi facilisis porta volutpat. Fusce adipiscing, mauris quis congue tincidunt, sapien purus suscipit odio, quis dictum odio
tortor in sem. Ut sit amet libero nec orci mattis fringilla. Praesent eu ipsum in sapien tincidunt molestie sed ut magna. Nam accumsan dui at orci rhoncus pharetra tincidunt elit ullamcorper. Sed ac mauris ipsum. Nullam imperdiet sapien id purus
pretium id aliquam mi ullamcorper.</p>
</div>
</li>
<li class="tab-header-and-content">
<a href="javascript:void(0)" class="tab-link">Another Tab</a>
<div class="tab-content">
<p>Ut laoreet augue et neque pretium non sagittis nibh pulvinar. Etiam ornare tincidunt orci quis ultrices. Pellentesque ac sapien ac purus gravida ullamcorper. Duis rhoncus sodales lacus, vitae adipiscing tellus pharetra sed. Praesent bibendum lacus
quis metus condimentum ac accumsan orci vulputate. Aenean fringilla massa vitae metus facilisis congue. Morbi placerat eros ac sapien semper pulvinar. Vestibulum facilisis, ligula a molestie venenatis, metus justo ullamcorper ipsum, congue aliquet
dolor tortor eu neque. Sed imperdiet, nibh ut vestibulum tempor, nibh dui volutpat lacus, vel gravida magna justo sit amet quam. Quisque tincidunt ligula at nisl imperdiet sagittis. Morbi rutrum tempor arcu, non ultrices sem semper a. Aliquam
quis sem mi.</p>
</div>
</li>
<li class="tab-header-and-content">
<a href="javascript:void(0)" class="tab-link">Third</a>
<div class="tab-content">
<p>Donec mattis mauris gravida metus laoreet non rutrum sem viverra. Aenean nibh libero, viverra vel vestibulum in, porttitor ut sapien. Phasellus tempor lorem id justo ornare tincidunt. Nulla faucibus, purus eu placerat fermentum, velit mi iaculis
nunc, bibendum tincidunt ipsum justo eu mauris. Nulla facilisi. Vestibulum vel lectus ac purus tempus suscipit nec sit amet eros. Nullam fringilla, enim eu lobortis dapibus, quam magna tincidunt nibh, sit amet imperdiet dolor justo congue turpis.</p>
</div>
</li>
<li class="tab-header-and-content">
<a href="javascript:void(0)" class="tab-link">Last Item</a>
<div class="tab-content">
<p>Sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Phasellus dui urna.</p>
</div>
</li>
<li class="nextContainer">
<a href="javascript:void(0)" class="nextContaner__link">Next</a>
</li>
</ul>
&#13;