【发布时间】:2022-02-11 00:14:05
【问题描述】:
大家好,我有一个包含三个选择按钮的表单,当页面加载时会预先选择其中的“分发”,其中包含全名、密码和位置等信息。如何使用JS创建点击效果,当任何按钮被选中时,预选,取消选择,内容发生变化。为了更清楚,这里有一些图片可以进一步解释
这是我的代码:
* {
box-sizing: border-box;
list-style: none;
text-decoration: none;
padding: 0;
margin: 0;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
display: flex;
font-size: 16px;
user-select: none;
}
/* APPLICATION */
.applicant {
width: 60%;
margin: auto;
text-align: left;
margin: 90px auto;
padding-top: 100px;
padding-bottom: 100px;
}
.login-center {
height: 100%;
flex-basis: 41%;
background: #ffffff;
padding: 35px 5px 0px 5px;
box-sizing: border-box;
box-shadow: 0 0 50px 0px #e1e1e1;
}
.text h2 {
text-align: center;
font-size: 35px;
font-weight: 600;
color: #000;
}
.links {
text-align: center;
margin-left: -20px;
margin-right: -20px;
margin: 0 auto;
padding-top: 50px;
}
.app-button {
color: #c4c4c4;
background-color: #ffffff;
border: 1px solid #000;
font-weight: bold;
font-size: 17px;
width: 200px;
margin: 0 20px;
display: inline-block;
line-height: 40px;
padding: 5px;
cursor: pointer;
}
.app-button:hover {
background: #c4c4c4;
color: #000000;
transition: 0.5s;
}
/* ACTIVE STATE */
.links .active,
.app-button:hover {
border: 1px solid #c4c4c4;
background-color: #c4c4c4;
color: #000;
}
/* FORM */
.form input::placeholder {
font-size: 14px;
color: #000;
}
.form label {
color: #000;
margin: 20px 0;
font-size: 17px;
}
.form-u {
margin: 70px 0;
padding: 0px 100px;
}
.form input {
width: 100%;
padding: 20px;
margin: 20px 0;
box-sizing: border-box;
border: none;
outline: none;
background: #ffffff;
border: 1.7px solid #e1e1e1;
}
.form input:focus {
border-color: #c4c4c4;
box-shadow: 0 0 15px 0px #e1e1e1;
}
.button-u {
color: #c4c4c4;
background-color: #000;
border: 1px solid rg#c4c4c4;
font-weight: bold;
font-size: 17px;
width: 100%;
margin: 40px 0;
display: inline-block;
line-height: 40px;
padding: 5px;
cursor: pointer;
}
/* DROPDOWN FOR LOCATION*/
.form input {
font-size: 15px;
color: #000;
}
.selector {
width: 100%;
padding-top: 20px;
margin-bottom: 25px;
position: relative;
}
#selectField p {
font-size: 15px;
}
#selectField {
width: 100%;
background: #ffffff;
box-sizing: border-box;
border: 1px solid #c4c4c4;
padding: 20px 20px;
color: #000;
font-size: 15px;
display: flex;
align-items: center;
justify-content: space-between;
cursor: pointer;
position: relative;
}
<!--Form-->
<section class="applicant">
<div class="login-center">
<div class="text">
<h2>CREATE</h2>
</div>
<div class="links">
<button type="button" class="app-button active">Distribute</button>
<button type="button" class="app-button">Buy</button>
<button type="button" class="app-button">Sell</button>
</div>
<div class="form-u">
<form action="" class="form">
<label for="uname"><b>Full Name:</b></label>
<input type="text" name="name=" Enter full name "required">
<label for="psw "><b>Password:</b></label>
<input type="password " name="password " placeholder="Enter password " required>
<label for="sem "><b>Location:</b></label>
<div class="selector ">
<div id="selectField ">
<p id="selectText ">Select a Location</p>
<img src="logo/arrow_down.png " alt=" " id="arrowIcon ">
</div>
</div>
<button type="submit " class="button-u ">SUBMIT</button>
</form>
</div>
</div>
</section>
总而言之,我希望能够单击所有按钮,并且单击的每个按钮应该具有从图像中看到的不同内容。希望我足够清楚。谢谢
【问题讨论】:
标签: javascript html css