gpt4 book ai didi

javascript - 使用html中的链接调用JS函数

转载 作者:行者123 更新时间:2023-11-30 13:47:08 25 4
gpt4 key购买 nike

我想将我的 div 设置为,如果我调用 sign upsign in 隐藏,反之亦然。我写了这段 JS 代码,但我无法调用这些函数来应用上述场景。碰巧的是,这两个 divs 同时出现在窗口上,这是不可取的。我应该怎么做,以便每当我按下登录链接时,注册 div 隐藏,类似地,当我点击新建时帐户登录 div 隐藏。

$(document).ready(function() {
$("#signIn").click(function() {
$(".signUpHide").hide(600);
$(".signInShow").show(600);
$(this).hide();
$("#signUp").show();
});
});

$(document).ready(function() {
$("#signUp").click(function() {
$(".signInHide").hide(600);
$(".signUpShow").show(600);
$(this).hide();
$("#signIn").show();
});
});
body {
height: 100vh;
width: 208vh;
}

.leftPanel {
background-color: #660033;
width: 70%;
height: 100%;
float: left;
position: absolute;
}

.rightPanel {
background-color: white;
width: 30%;
height: 100%;
float: right;
}

.signInClass {}

.signInHide {}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="rightPanel">
<div class="container">
<div class="row" style="margin-top: 30px">
<label class="col-md-3"></label>
</div>

<div class="signUpHide signUpShow">
<div class="row" style="margin-top: 30px">
<label class="col-md-2"></label>
<h1 class="col-md-10"><a name="SignUp">Sign Up</a></h1>
<label class="col-md-2"></label>
<label>or <a href="#SignIn">sign in</a> to your account</label>
</div>

<form action="bbSignUp.php" method="post">

<div class="row" style="margin-top: 20px">
<label class="col-md-2"></label>
<input type="text" class="form-control col-md-8" placeholder="Username" name="user-name">
<label class="col-md-2"></label>
</div>

<div class="row" style="margin-top: 20px">
<label class="col-md-2"></label>
<input type="email" class="form-control col-md-8" placeholder="Email" name="e-mail" required="true">
<label class="col-md-2"></label>
</div>

<div class="row" style="margin-top: 20px">
<label class="col-md-2"></label>
<input type="password" class="form-control col-md-8" placeholder="Password" name="pass-word" required="true">
<label class="col-md-2"></label>
</div>

<div class="row" style="margin-top: 20px">
<label class="col-md-2"></label>
<label class="col-md-8" style="font-size: 11px">This page is protected by reCAPTCHA, and subject to the Google Privacy Policy and Terms of service.</label>
<label class="col-md-2"></label>
</div>

<div class="row" style="margin-top: 20px">
<label class="col-md-2"></label>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="defaultUnchecked" onchange="document.getElementById('signUpButton').disabled = !this.checked;">
<label class="custom-control-label" for="defaultUnchecked">I agree to the Terms and Conditions</label>
</div>

<label class="col-md-2"></label>
</div>

<div class="row" style="margin-top: 20px">
<label class="col-md-2"></label>
<button type="submit" class="btn btn-primary btn-block col-md-8" name="signUpButton" id="signUpButton" disabled="true">Sign Up</button>
<label class="col-md-2"></label>

</div>
</form>
</div>

<div class="signInShow signInHide">

<div class="row" style="margin-top: 30px">
<label class="col-md-2"></label>
<h1 class="col-md-10"><a name="SignIn">Sign In</a></h1>
<label class="col-md-2"></label>
<label>or <a href="#SignUp">create an account</a></label>
</div>

<form action="bbSignIn.php" method="post">

<div class="row" style="margin-top: 20px">
<label class="col-md-2"></label>
<input type="email" class="form-control col-md-8" placeholder="Email" name="e-mail1" required="true">
<label class="col-md-2"></label>
</div>

<div class="row" style="margin-top: 20px">
<label class="col-md-2"></label>
<input type="password" class="form-control col-md-8" placeholder="Password" name="pass-word1" required="true">
<label class="col-md-2"></label>
</div>

<div class="row" style="margin-top: 20px">
<label class="col-md-2"></label>
<label class="col-md-8" style="font-size: 11px">This page is protected by reCAPTCHA, and subject to the Google Privacy Policy and Terms of service.</label>
<label class="col-md-2"></label>
</div>

<div class="row" style="margin-top: 20px">
<label class="col-md-2"></label>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="defaultUnchecked1" onchange="document.getElementById('signInButton').disabled = !this.checked;">
<label class="custom-control-label" for="defaultUnchecked1">I agree to the Dropbox Terms</label>
</div>

<label class="col-md-2"></label>
</div>

<div class="row" style="margin-top: 20px">
<label class="col-md-2"></label>
<button type="submit" class="btn btn-primary btn-block col-md-8" name="signInButton" id="signInButton" disabled="true">Sign In</button>
<label class="col-md-2"></label>
</div>
</form>
</div>
</div>
</div>

最佳答案

首先,代码可以重构为单个document.ready,您可以使用toggle() 显示/隐藏 元素。其次,id 的用法需要固定为 id="SignIn" 而不是 href="#SignIn"

$(document).ready(function() {
$("#signIn,#signUp").click(function() {
$(".signIn, .signUp").toggle();
});
});
height: 100vh;
width: 208vh;

}
.leftPanel {
background-color: #660033;
width: 70%;
height: 100%;
float: left;
position: absolute;
}
.rightPanel {
background-color: white;
width: 30%;
height: 100%;
float: right;
}
.signInClass {}
.signInHide {}
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>

<div class="rightPanel">
<div class="container">
<div class="row" style="margin-top: 30px">
<label class="col-md-3"></label>
</div>

<div class="signUp" style="display:none;">
<div class="row" style="margin-top: 30px">
<label class="col-md-2"></label>
<h1 class="col-md-10"><a name="SignUp">Sign Up</a></h1>
<label class="col-md-2"></label>
<label>or <a href="#" id="signUp">sign in</a> to your account</label>
</div>

<form action="bbSignUp.php" method="post">

<div class="row" style="margin-top: 20px">
<label class="col-md-2"></label>
<input type="text" class="form-control col-md-8" placeholder="Username" name="user-name">
<label class="col-md-2"></label>
</div>

<div class="row" style="margin-top: 20px">
<label class="col-md-2"></label>
<input type="email" class="form-control col-md-8" placeholder="Email" name="e-mail" required="true">
<label class="col-md-2"></label>
</div>

<div class="row" style="margin-top: 20px">
<label class="col-md-2"></label>
<input type="password" class="form-control col-md-8" placeholder="Password" name="pass-word" required="true">
<label class="col-md-2"></label>
</div>

<div class="row" style="margin-top: 20px">
<label class="col-md-2"></label>
<label class="col-md-8" style="font-size: 11px">This page is protected by reCAPTCHA, and subject to the Google Privacy Policy and Terms of service.</label>
<label class="col-md-2"></label>
</div>

<div class="row" style="margin-top: 20px">
<label class="col-md-2"></label>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="defaultUnchecked" onchange="document.getElementById('signUpButton').disabled = !this.checked;">
<label class="custom-control-label" for="defaultUnchecked">I agree to the Terms and Conditions</label>
</div>

<label class="col-md-2"></label>
</div>

<div class="row" style="margin-top: 20px">
<label class="col-md-2"></label>
<button type="submit" class="btn btn-primary btn-block col-md-8" name="signUpButton" id="signUpButton" disabled="true">Sign Up</button>
<label class="col-md-2"></label>

</div>
</form>
</div>

<div class="signIn">

<div class="row" style="margin-top: 30px">
<label class="col-md-2"></label>
<h1 class="col-md-10"><a name="SignIn">Sign In</a></h1>
<label class="col-md-2"></label>
<label>or <a href="#" id="signIn">create an account</a></label>
</div>

<form action="bbSignIn.php" method="post">

<div class="row" style="margin-top: 20px">
<label class="col-md-2"></label>
<input type="email" class="form-control col-md-8" placeholder="Email" name="e-mail1" required="true">
<label class="col-md-2"></label>
</div>

<div class="row" style="margin-top: 20px">
<label class="col-md-2"></label>
<input type="password" class="form-control col-md-8" placeholder="Password" name="pass-word1" required="true">
<label class="col-md-2"></label>
</div>

<div class="row" style="margin-top: 20px">
<label class="col-md-2"></label>
<label class="col-md-8" style="font-size: 11px">This page is protected by reCAPTCHA, and subject to the Google Privacy Policy and Terms of service.</label>
<label class="col-md-2"></label>
</div>

<div class="row" style="margin-top: 20px">
<label class="col-md-2"></label>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="defaultUnchecked1" onchange="document.getElementById('signInButton').disabled = !this.checked;">
<label class="custom-control-label" for="defaultUnchecked1">I agree to the Dropbox Terms</label>
</div>

<label class="col-md-2"></label>
</div>

<div class="row" style="margin-top: 20px">
<label class="col-md-2"></label>
<button type="submit" class="btn btn-primary btn-block col-md-8" name="signInButton" id="signInButton" disabled="true">Sign In</button>
<label class="col-md-2"></label>
</div>
</form>
</div>
</div>
</div>

关于javascript - 使用html中的链接调用JS函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59079615/

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