我手风琴中有单选按钮,根据选择的单选按钮,它会提示不同的输出。 (还有额外的CSS)
var acc = document.getElementsByClassName("accordion");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].onclick = function(){
if(!this.classList.contains("active")) {
closeAccordions();
}
this.classList.toggle("active");
this.nextElementSibling.classList.toggle("show");
}
}
function closeAccordions() {
for (i = 0; i < acc.length; i++) {
acc[i].classList.remove("active");
acc[i].nextElementSibling.classList.remove("show");
}
}
var chanceoflive5 = 1;
var user;
function choose(choice){
user = choice;
}
function changechanceoflive2(){
if (user == 'bolts') {
chanceoflive5 = 1;
}
else if (user == 'plates') {
chanceoflive5 = 2;
}
}
var chanceoflive6 = 1;
var user2;
function choose2(choice2){
user = choice2;
}
function changechanceoflive3(){
if (user2 == 'tie') {
chanceoflive6 = 1;
}
else if (user2 == 'struts') {
chanceoflive6 = 2;
}
}
function nextpage(){
var chanceoflive7 = chanceoflive5 + chanceoflive6;
alert(chanceoflive7);
}
&#13;
button.accordion {
background-color: #eee;
color: #444;
cursor: pointer;
padding: 18px;
width: 100%;
border: none;
text-align: left;
outline: none;
font-size: 15px;
transition: 0.4s;
}
button.accordion.active, button.accordion:hover {
background-color: #ddd;
}
button.accordion:after {
content: '\002B';
color: #777;
font-weight: bold;
float: right;
margin-left: 5px;
}
button.accordion.active:after {
content: "\2212";
}
div.panel {
padding: 0 18px;
background-color: white;
max-height: 0;
overflow: hidden;
transition: 0.6s ease-in-out;
opacity: 0;
}
div.panel.show {
opacity: 1;
max-height: 500px;
}
body {
font-family: sans-serif;
font-weight: normal;
margin: 10px;
color: #999;
}
form {
margin: 40px 0;
}
div {
clear: both;
margin: 0 50px;
}
label {
border-radius: 3px;
border: 1px solid #D1D3D4
}
/* hide input */
input.radio:empty {
margin-left: -999px;
}
/* style label */
input.radio:empty ~ label {
position: relative;
float: left;
line-height: 2.5em;
text-indent: 3.25em;
margin-top: 2em;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
input.radio:empty ~ label:before {
position: absolute;
display: block;
top: 0;
bottom: 0;
left: 0;
content: '';
width: 2.5em;
background: #D1D3D4;
border-radius: 3px 0 0 3px;
}
/* toggle hover */
input.radio:hover:not(:checked) ~ label:before {
content:'\2714';
text-indent: .9em;
color: #C2C2C2;
}
input.radio:hover:not(:checked) ~ label {
color: #888;
}
/* toggle on */
input.radio:checked ~ label:before {
content:'\2714';
text-indent: .9em;
color: #9CE2AE;
background-color: #4DCB6D;
}
input.radio:checked ~ label {
color: #777;
}
button.accordion {
background-color: #eee;
color: #444;
cursor: pointer;
padding: 18px;
width: 100%;
border: none;
text-align: left;
outline: none;
font-size: 15px;
transition: 0.4s;
}
button.accordion.active, button.accordion:hover {
background-color: #ddd;
}
button.accordion:after {
content: '\002B';
color: #777;
font-weight: bold;
float: right;
margin-left: 5px;
}
button.accordion.active:after {
content: "\2212";
}
div.panel {
padding: 0 18px;
background-color: white;
max-height: 0;
overflow: hidden;
transition: 0.6s ease-in-out;
opacity: 0;
}
div.panel.show {
opacity: 1;
max-height: 500px;
}
body {
font-family: sans-serif;
font-weight: normal;
margin: 10px;
color: #999;
}
form {
margin: 40px 0;
}
div {
clear: both;
margin: 0 50px;
}
label {
border-radius: 3px;
border: 1px solid #D1D3D4
}
/* hide input */
input.radio:empty {
margin-left: -999px;
}
/* style label */
input.radio:empty ~ label {
position: relative;
float: left;
line-height: 2.5em;
text-indent: 3.25em;
margin-top: 2em;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
input.radio:empty ~ label:before {
position: absolute;
display: block;
top: 0;
bottom: 0;
left: 0;
content: '';
width: 2.5em;
background: #D1D3D4;
border-radius: 3px 0 0 3px;
}
/* toggle hover */
input.radio:hover:not(:checked) ~ label:before {
content:'\2714';
text-indent: .9em;
color: #C2C2C2;
}
input.radio:hover:not(:checked) ~ label {
color: #888;
}
/* toggle on */
input.radio:checked ~ label:before {
content:'\2714';
text-indent: .9em;
color: #9CE2AE;
background-color: #4DCB6D;
}
input.radio:checked ~ label {
color: #777;
}
&#13;
<hr>
<button class="accordion">Foundation Bolting</button>
<div class="panel">
<div>
<input type="radio" name="radio" id="radio1-1" class="radio" onclick="choose('bolts')" checked/>
<label for="radio1-1">Foundation Bolts</label>
</div>
<div>
<input type="radio" name="radio" id="radio1-2" class="radio" onclick="choose('plates')">
<label for="radio1-2">Foundation Plates</label>
</div>
</div>
<hr>
<button class="accordion">Wall Bracing</button>
<div class="panel">
<div>
<input type="radio" name="radio2" id="radio2-1" class="radio" onclick="choose2('tie')" checked/>
<label for="radio2-1">Strong Tie Retrofit Connectors</label>
</div>
<div>
<input type="radio" name="radio2" id="radio2-2" class="radio" onclick="choose2('struts')">
<label for="radio2-2">Angled Iron Struts</label>
</div>
</div>
<hr>
<form action="">
<div class="wrapper">
<button class="button" onClick="changechanceoflive2(); changechanceoflive3(); nextpage()" align=center>Submit</button>
</div>
</form>
&#13;
当您点击每个列表的底部选项时,它应该警告4,但它会提醒3.为什么?