gpt4 book ai didi

javascript - 如何在两个链接之间使用 toggleClass 方法

转载 作者:太空宇宙 更新时间:2023-11-03 20:05:39 41 4
gpt4 key购买 nike

我正在开发一个登录和注册表单,我必须在其中从登录链接切换到注册页面。因此,对于用户来说,为了知道他在哪个链接中,我想在他单击该链接时为该特定链接着色。所以我为它使用了 toggleClass 但它不能正常工作。我在下面发布了我所做的代码。

这是 jsfiddle link

HTML

 <div class="container">
<div class="frame">
<div class="nav">
<ul>
<li><a class="btn">Sign in</a></li>
<li><a class="btn1">Sign up </a></li>
</ul>
</div>


</div></div>

CSS

body {
margin:0;
background-image: url("/resources/images/BackGroundSoccer.jpg");
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
}

/* Style the tab */
.lol {
overflow: hidden;

background-color: #e23e36;
width:25%;
position:fixed;
height:62px;
z-index: 1;
}


.empty {
display:inline-block;
background-color: #e23e36;
width:10%;
text-align:center;
margin-left:35%;
}
.shy {
display:inline-block;
background-color: #e23e36;
width:15%;
text-align:center;
margin-left:20%;
}

.tab {

background-color: #e23e36;
width:100%;
position:fixed;
z-index: 1;
margin-left:24.9%;
height:62px;
}

.tablinks3 {
color:white;
font-size: 22px;
font-family:"Arial Black", Gadget, sans-fseri;
margin-left:24.9%;


}

.container {
width: 100%;
padding-top: 100px;
padding-bottom: 100px;
}

.frame {
height: 575px;
width: 430px;
background:
linear-gradient(
rgba(35,43,85,0.75),
rgba(35,43,85,0.95));
background-size: cover;
margin-left: auto;
margin-right: auto;
border-top: solid 1px rgba(255,255,255,.5);
border-radius: 5px;
box-shadow: 0px 2px 7px rgba(0,0,0,0.2);
overflow: hidden;
transition: all .5s ease;

}
.nav {
padding-top:40px;
}

li {

padding-left: 10px;
font-size: 18px;
display: inline;
text-align: left;
text-transform: uppercase;
padding-right: 10px;
color: #ffffff;

}

.btn {
cursor : pointer;
color: rgb(255,255,255);
padding: 10px;


}
.btn1 {
cursor : pointer;
color: rgb(255,255,255);
padding: 10px;
}


.form-signin {
padding-left:30px;
padding-top:50px;
padding-right:30px;
}

label {
font-weight: 400;
text-transform: uppercase;
font-size: 20px;
padding-left: 15px;
padding-bottom: 10px;
color: rgba(255,255,255,.7);
display: block;
}

.form-styling {
width: 100%;
height: 35px;
border: none;
padding-left: 15px;
border-radius: 15px;
margin-bottom: 10px;
background: rgba(255,255,255,.2);
color :rgb(255,255,255);
}

.btn-animate {
float: left;
font-weight: 400;
text-transform: uppercase;
font-size: 20px;
text-align: center;
color: rgba(255,255,255, 1);
padding-top: 8px;
width: 100%;
height: 35px;
border: none;
border-radius: 20px;
margin-top: 30px;
margin-bottom:20px;
background-color: rgba(16,89,255, 1);
left: 0px;
top: 0px;
cursor: pointer;
transition: all .5s ease, top .5s ease .5s, height .5s ease .5s, background-color .5s ease .75s;
}

.check
{
font-size : 20px;
padding-right: 10px;
font-weight: 400;
text-transform: uppercase;
color: rgba(255,255,255,.7);
padding-left :15px;

}

.forgot
{
color: rgba(255,255,255,.7);
font-size:15px;
font-weight:400px;
cursor:pointer;
text-decoration:underline;
padding-left : 165px;

}

:focus {outline: none;
}
.toggle {
background-color: rgb(0,0,0);
}
.toggle1 {
background-color: transparent;
}

JQuery

$(document).ready(function(){
$(".signin-show").show();
$(".signup-show").hide();
$(".btn").toggleClass('toggle');
$(".btn1").click(function(){
$(".signin-show").hide();
$(".signup-show").show();
$(".btn1").toggleClass('toggle');
$(".btn").toggleClass('toggle1');
});
$(".btn").click(function(){
$(".signin-show").show();
$(".signup-show").hide();
$(".btn").toggleClass('toggle');

});

});

我们将不胜感激。

最佳答案

你的代码可以总结为这3行代码

  1. 从所有元素中删除 toggle
  2. 给被点击的元素添加切换类

    $(".btn").click(function(){
    $(".btn").removeClass("toggle")
    $(this).addClass("toggle")
    })

这是 snippet

关于javascript - 如何在两个链接之间使用 toggleClass 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50372041/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com