答案 0 :(得分:2)
justed selectedIndex吗?
window.onload=_=>{ dropdown.selectedIndex = 3 }
SetDefault.onclick=_=>{ dropdown.selectedIndex = 3 }
<select id="dropdown">
<option value="mech">101</option>
<option value="cse">201</option>
<option value="ece">4301</option>
<option value="Select" selected disabled="disabled">select the branch code</option>
</select>
<button id="SetDefault"> Set Default</button>
带有“ TAB”的示例...
window.onload=_=>{ dropdown.selectedIndex = 3 }
tab1.onclick=_=>{ dropdown.selectedIndex = 3; }
.tabset > input[type="radio"] {
position: absolute;
left: -200vw;
}
.tabset .tab-panel {
display: none;
}
.tabset > input:first-child:checked ~ .tab-panels > .tab-panel:first-child,
.tabset > input:nth-child(3):checked ~ .tab-panels > .tab-panel:nth-child(2),
.tabset > input:nth-child(5):checked ~ .tab-panels > .tab-panel:nth-child(3),
.tabset > input:nth-child(7):checked ~ .tab-panels > .tab-panel:nth-child(4),
.tabset > input:nth-child(9):checked ~ .tab-panels > .tab-panel:nth-child(5),
.tabset > input:nth-child(11):checked ~ .tab-panels > .tab-panel:nth-child(6) {
display: block;
}
/*
Styling
*/
body {
font: 16px/1.5em "Overpass", "Open Sans", Helvetica, sans-serif;
color: #333;
font-weight: 300;
}
.tabset > label {
position: relative;
display: inline-block;
padding: 15px 15px 25px;
border: 1px solid transparent;
border-bottom: 0;
cursor: pointer;
font-weight: 600;
}
.tabset > label::after {
content: "";
position: absolute;
left: 15px;
bottom: 10px;
width: 22px;
height: 4px;
background: #8d8d8d;
}
.tabset > label:hover,
.tabset > input:focus + label {
color: #06c;
}
.tabset > label:hover::after,
.tabset > input:focus + label::after,
.tabset > input:checked + label::after {
background: #06c;
}
.tabset > input:checked + label {
border-color: #ccc;
border-bottom: 1px solid #fff;
margin-bottom: -1px;
}
.tab-panel {
padding: 30px 0;
border-top: 1px solid #ccc;
}
/*
Demo purposes only
*/
*,
*:before,
*:after {
box-sizing: border-box;
}
body {
padding: 30px;
}
.tabset {
max-width: 65em;
}
<div class="tabset">
<!-- Tab 1 -->
<input type="radio" name="tabset" id="tab1" checked>
<label for="tab1">Select</label>
<!-- Tab 2 -->
<input type="radio" name="tabset" id="tab2">
<label for="tab2">input text</label>
<!-- Tab 3 -->
<input type="radio" name="tabset" id="tab3">
<label for="tab3">something</label>
<div class="tab-panels">
<section id="foo_1" class="tab-panel">
<h2>Select</h2>
<p>
<select id="dropdown">
<option value="mech">101</option>
<option value="cse">201</option>
<option value="ece">4301</option>
<option value="Select" selected disabled="disabled">select the branch code</option>
</select>
</p>
</section>
<section id="foo_2" class="tab-panel">
<h2>input_text</h2>
<p>
<textarea name="bob" id="bob" cols="30" rows="10"></textarea>
</p>
</section>
<section id="foo_3" class="tab-panel">
<h2>something</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut congue felis ac porttitor elementum.
Vivamus auctor semper mollis. Etiam ac nibh nulla. Etiam cursus malesuada ante, et cursus risus pellentesque et.
Proin ligula orci, placerat eu lobortis eu, pretium nec ex. Phasellus rutrum mauris nisl, a placerat lacus
tempus a.
Morbi consequat, felis ut sodales mollis, ante elit mollis felis, vitae volutpat lorem erat at orci.
Etiam porta quam nec blandit faucibus. Quisque finibus enim a tincidunt posuere.
Nullam porta odio nec nibh volutpat, quis efficitur nulla iaculis. Phasellus dictum porttitor tellus eget
bibendum.
Donec faucibus, felis scelerisque tempus sagittis, ligula ligula pellentesque nisl, eu consectetur nisi sapien
sit amet enim.
Sed diam mi, tempus vel faucibus tempus, pulvinar quis neque. Cras vulputate lacus nibh.
</p>
<p>
tab system from : https://codepen.io/markcaron/pen/MvGRYV
</p>
</section>
</div>
</div>