我试图让AJAX标签正常工作。当前代码的问题是它没有为活动选项卡设置样式。
可能我需要用一些javascript代码解决这个问题但不知道从哪里开始。
HTML
$("h2").addClass("white");
$(document).ready(function () {
// load index page when the page loads
$("#response").html("DEFAULT");
$("#page1").click(function () {
// load home page on click
$("#response").html("<h2> Welcome </h2><p>Sed porttitor lectus nibh. Cras ultricies ligula sed magna dictum porta. Praesent sapien massa, convallis a pellentesque nec, egestas non nisi. <br/> Curabitur arcu erat, accumsan id imperdiet et, porttitor at sem. Nulla quis lorem ut libero malesuada feugiat. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>");
});
$("#page2").click(function () {
// load about page on click
$("#response").html("TESTING 2");
});
$("#page3").click(function () {
// load contact form onclick
$("#response").html("TESTING 3");
});
$("#page4").click(function () {
// load contact form onclick
$("#response").html("TESTING 4");
});
$("#page5").click(function () {
// load contact form onclick
$("#response").html("TESTING 5");
});
});
&#13;
li {
display: inline-block;
margin-right: 2px;
}
li a {
padding: 4px;
color:#0086ca;
text-decoration: none;
}
.white {
color: green;
}
.contentarea {
margin-top: 30px;
width: 100%;
padding: 40px 50px;
background-color: #0086ca;
color: white;
text-align: left;
font-size: 24px;
}
/* --------------------------------
Multi steps indicator
-------------------------------- */
@media only screen and (min-width: 768px) {
.cd-multi-steps {
/* reset style */
background-color: transparent;
padding: 0;
text-align: center;
}
.cd-multi-steps li {
position: relative;
float: none;
margin: 0.4em 40px 0.4em 0;
}
.cd-multi-steps li:last-of-type {
margin-right: 0;
}
.cd-multi-steps li::after {
/* this is the line connecting 2 adjacent items */
position: absolute;
content: '';
height: 4px;
background: #edeff0;
/* reset style */
margin: 0;
}
.cd-multi-steps li.visited::after {
background-color: #96c03d;
}
.cd-multi-steps li > *, .cd-multi-steps li.current > * {
position: relative;
color: #2c3f4c;
}
.cd-multi-steps.custom-separator li::after {
/* reset style */
height: 4px;
background: #edeff0;
}
.cd-multi-steps.text-center li::after {
width: 100%;
top: 50%;
left: 100%;
-webkit-transform: translateY(-50%) translateX(-1px);
-moz-transform: translateY(-50%) translateX(-1px);
-ms-transform: translateY(-50%) translateX(-1px);
-o-transform: translateY(-50%) translateX(-1px);
transform: translateY(-50%) translateX(-1px);
}
.cd-multi-steps.text-center li > * {
z-index: 1;
padding: .6em 1em;
border-radius: .25em;
background-color: #edeff0;
}
.no-touch .cd-multi-steps.text-center a:hover {
background-color: #2c3f4c;
}
.cd-multi-steps.text-center li.current > *, .cd-multi-steps.text-center li.visited > * {
color: #ffffff;
background-color: #96c03d;
}
.cd-multi-steps.text-center.custom-icons li.visited a::before {
/* change the custom icon for the visited item - check icon */
background-position: 0 -60px;
}
.cd-multi-steps.text-top li, .cd-multi-steps.text-bottom li {
width: 80px;
text-align: center;
}
.cd-multi-steps.text-top li::after, .cd-multi-steps.text-bottom li::after {
/* this is the line connecting 2 adjacent items */
position: absolute;
left: 50%;
/* 40px is the <li> right margin value */
width: calc(100% + 40px);
}
.cd-multi-steps.text-top li > *::before, .cd-multi-steps.text-bottom li > *::before {
/* this is the spot indicator */
content: '';
position: absolute;
z-index: 1;
left: 50%;
right: auto;
-webkit-transform: translateX(-50%);
-moz-transform: translateX(-50%);
-ms-transform: translateX(-50%);
-o-transform: translateX(-50%);
transform: translateX(-50%);
height: 12px;
width: 12px;
border-radius: 50%;
background-color: #edeff0;
}
.cd-multi-steps.text-top li.visited > *::before,
.cd-multi-steps.text-top li.current > *::before, .cd-multi-steps.text-bottom li.visited > *::before,
.cd-multi-steps.text-bottom li.current > *::before {
background-color: #96c03d;
}
.no-touch .cd-multi-steps.text-top a:hover, .no-touch .cd-multi-steps.text-bottom a:hover {
color: #96c03d;
}
.no-touch .cd-multi-steps.text-top a:hover::before, .no-touch .cd-multi-steps.text-bottom a:hover::before {
box-shadow: 0 0 0 3px rgba(150, 192, 61, 0.3);
}
.cd-multi-steps.text-top li::after {
/* this is the line connecting 2 adjacent items */
bottom: 4px;
}
.cd-multi-steps.text-top li > * {
padding-bottom: 20px;
}
.cd-multi-steps.text-top li > *::before {
/* this is the spot indicator */
bottom: 0;
}
.cd-multi-steps.text-bottom li::after {
/* this is the line connecting 2 adjacent items */
top: 3px;
}
.cd-multi-steps.text-bottom li > * {
padding-top: 20px;
}
.cd-multi-steps.text-bottom li > *::before {
/* this is the spot indicator */
top: 0;
}
}
/* --------------------------------
Add a counter to the multi-steps indicator
-------------------------------- */
.cd-multi-steps.count li {
counter-increment: steps;
}
.cd-multi-steps.count li > *::before {
content: counter(steps) " - ";
}
@media only screen and (min-width: 768px) {
.cd-multi-steps.text-top.count li > *::before,
.cd-multi-steps.text-bottom.count li > *::before {
/* this is the spot indicator */
content: counter(steps);
height: 26px;
width: 26px;
line-height: 26px;
font-size: 1.4rem;
color: #ffffff;
}
.cd-multi-steps.text-top.count li:not(.current) em::before,
.cd-multi-steps.text-bottom.count li:not(.current) em::before {
/* steps not visited yet - counter color */
color: #2c3f4c;
}
.cd-multi-steps.text-top.count li::after {
bottom: 11px;
}
.cd-multi-steps.text-top.count li > * {
padding-bottom: 34px;
}
.cd-multi-steps.text-bottom.count li::after {
top: 11px;
}
.cd-multi-steps.text-bottom.count li > * {
padding-top: 34px;
}
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav>
<ul class="cd-multi-steps text-bottom count">
<li class="current"><a href="#tabs-1" id="page1" class="tab">page 1</a>
</li>
<li><a href="#tabs-2" id="page2" class="tab">page 2</a>
</li>
<li><a href="#tabs-3" id="page3" class="tab">page 3</a>
</li>
<li><a href="#tabs-4" id="page4" class="tab">page 4</a>
</li>
<li><a href="#tabs-5" id="page5" class="tab">page 5</a>
</li>
</ul>
</nav>
<div class="contentarea" id="response"></div>
&#13;
如何让活动标签脱颖而出?
感谢。
答案 0 :(得分:0)
每次id
都不需要点击。我已经简化了您的代码并在点击时添加了.active
。希望它有所帮助。
$("h2").addClass("white");
$(document).ready(function() {
// load index page when the page loads
var data = {
'#tabs-1':'Testing 1',
'#tabs-2':'Testing 2',
'#tabs-3':'Testing 3',
'#tabs-4':'Testing 4',
'#tabs-5':'Testing 5'
};
$("#response").html("DEFAULT");
$('.tab').click(function(){
$('.tab').removeClass('active'); //remove .active from all
$(this).addClass('active'); //add .active to current pressed
href = $(this).attr('href');
$("#response").html(data[href]);
});
});
&#13;
li {
display: inline-block;
margin-right: 2px;
}
li a {
padding: 8px 4px;
color: #0086ca;
text-decoration: none;
}
li a.active {
color: white;
background:#0086ca;
}
.contentarea {
margin-top: 30px;
width: 100%;
padding: 40px 50px;
background-color: #0086ca;
color: white;
text-align: left;
font-size: 24px;
}
.cd-multi-steps.count li {
counter-increment: steps;
}
.cd-multi-steps.count li > *::before {
/*content: counter(steps)" - ";*/
}
@media only screen and (min-width: 768px) {
.cd-multi-steps.text-top.count li > *::before,
.cd-multi-steps.text-bottom.count li > *::before {
/* this is the spot indicator
content: counter(steps);*/
height: 26px;
width: 26px;
line-height: 26px;
font-size: 1.4rem;
color: #ffffff;
}
.cd-multi-steps.text-top.count li:not(.current) em::before,
.cd-multi-steps.text-bottom.count li:not(.current) em::before {
/* steps not visited yet - counter color */
color: #2c3f4c;
}
.cd-multi-steps.text-top.count li::after {
bottom: 11px;
}
.cd-multi-steps.text-top.count li > * {
padding-bottom: 34px;
}
.cd-multi-steps.text-bottom.count li::after {
top: 11px;
}
.cd-multi-steps.text-bottom.count li > * {
padding-top: 34px;
}
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav>
<ul class="cd-multi-steps text-bottom count">
<li class="current"><a href="#tabs-1" id="page1" class="tab">page 1</a>
</li>
<li class="current"><a href="#tabs-2" id="page2" class="tab">page 2</a>
</li>
<li><a href="#tabs-3" id="page3" class="tab">page 3</a>
</li>
<li><a href="#tabs-4" id="page4" class="tab">page 4</a>
</li>
<li><a href="#tabs-5" id="page5" class="tab">page 5</a>
</li>
</ul>
</nav>
<div class="contentarea" id="response"></div>
&#13;
答案 1 :(得分:0)
检查此代码可能有帮助
在点击功能中使用addClass()
$("li").click(function(){
$(this).addClass("active").siblings().removeClass('active');
})
$("#page1").click(function () {
// load home page on click
$("#response").html("<h2> Welcome </h2><p>Sed porttitor lectus nibh. Cras ultricies ligula sed magna dictum porta. Praesent sapien massa, convallis a pellentesque nec, egestas non nisi. <br/> Curabitur arcu erat, accumsan id imperdiet et, porttitor at sem. Nulla quis lorem ut libero malesuada feugiat. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>");
$("h2").addClass("white");
});
$(document).ready(function () {
// load index page when the page loads
$("#response").html("DEFAULT");
$("li").click(function(){
$(this).addClass("active").siblings().removeClass('active');
})
$("#page1").click(function () {
// load home page on click
$("#response").html("<h2> Welcome </h2><p>Sed porttitor lectus nibh. Cras ultricies ligula sed magna dictum porta. Praesent sapien massa, convallis a pellentesque nec, egestas non nisi. <br/> Curabitur arcu erat, accumsan id imperdiet et, porttitor at sem. Nulla quis lorem ut libero malesuada feugiat. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>");
$("h2").addClass("white");
});
$("#page2").click(function () {
// load about page on click
$("#response").html("TESTING 2");
});
$("#page3").click(function () {
// load contact form onclick
$("#response").html("TESTING 3");
});
$("#page4").click(function () {
// load contact form onclick
$("#response").html("TESTING 4");
});
$("#page5").click(function () {
// load contact form onclick
$("#response").html("TESTING 5");
});
});
&#13;
li {
display: inline-block;
margin-right: 2px;
}
li a {
padding: 4px;
color:#0086ca;
text-decoration: none;
}
.contentarea {
margin-top: 30px;
width: 100%;
padding: 40px 50px;
background-color: #0086ca;
color: white;
text-align: left;
font-size: 24px;
}
.cd-multi-steps.count li {
counter-increment: steps;
}
.cd-multi-steps.count li > *::before {
content: counter(steps) " - ";
}
@media only screen and (min-width: 768px) {
.cd-multi-steps.text-top.count li > *::before,
.cd-multi-steps.text-bottom.count li > *::before {
/* this is the spot indicator */
content: counter(steps);
height: 26px;
width: 26px;
line-height: 26px;
font-size: 1.4rem;
color: #ffffff;
}
.cd-multi-steps.text-top.count li:not(.current) em::before,
.cd-multi-steps.text-bottom.count li:not(.current) em::before {
/* steps not visited yet - counter color */
color: #2c3f4c;
}
.cd-multi-steps.text-top.count li::after {
bottom: 11px;
}
.cd-multi-steps.text-top.count li > * {
padding-bottom: 34px;
}
.cd-multi-steps.text-bottom.count li::after {
top: 11px;
}
.cd-multi-steps.text-bottom.count li > * {
padding-top: 34px;
}
}
.white{color:yellow}
li.active a{color:blue; border:1px solid;}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav>
<ul class="cd-multi-steps text-bottom count">
<li class="current"><a href="#tabs-1" id="page1" class="tab">page 1</a>
</li>
<li class="current"><a href="#tabs-2" id="page2" class="tab">page 2</a>
</li>
<li><a href="#tabs-3" id="page3" class="tab">page 3</a>
</li>
<li><a href="#tabs-4" id="page4" class="tab">page 4</a>
</li>
<li><a href="#tabs-5" id="page5" class="tab">page 5</a>
</li>
</ul>
</nav>
<div class="contentarea" id="response"></div>
&#13;