对于正在做的网站,我有此下拉列表
裸露下拉列表
<!DOCTYPE html>
<html>
<head>
<style>
p.sansserif {
font-family: Arial, Helvetica, sans-serif;
}
</style>
</head>
<body onload="myFunction()" text="white">
<p class="sansserif"> Select Your Phone Brand</p>
<select id="brand" onchange="myFunction()">
<option value="0">
<option value="1">Apple
<option value="2">Samsung
<option value="3">LG
<option value="4">Other
</select>
<div id="apple">
<p class="sansserif">Select Your Phone Model</p>
<select id="model1" onchange="myFunction()">
<option value="0">
<option value="1">iPhone Xs Max
<option value="2">iPhone Xs
<option value="3">iPhone X
<option value="4">iPhone 8+
<option value="5">iPhone 8
<option value="6">iPhone 7+
<option value="7">iPhone 7
<option value="8">iPhone 6s+
<option value="9">iPhone 6s
<option value="10">iPhone 6+
<option value="11">iPhone 6
<option value="12">iPhone 5SE
<option value="13">iPhone 5S
<option value="14">iPhone 5C
<option value="15">iPhone 5
<option value="16">Other
</select>
</div>
<div id="samsung">
<p class="sansserif">Select Your Phone Model</p>
<select id="model2" onchange="myFunction()">
<option value="0">
<option value="1">Galaxy S9+
<option value="2">Galaxy S9
<option value="3">Galaxy S8+
<option value="4">Galaxy S8
<option value="5">Galaxy S7 Edge
<option value="6">Galaxy S7
<option value="7">Galaxy S6 Edge+
<option value="8">Galaxy S6 Edge
<option value="9">Galaxy S6
<option value="10">Note 9
<option value="11">Note 8
<option value="12">Note 7
<option value="13">Note 5
<option value="14">Other
</select>
</div>
<div id="lg">
<p class="sansserif">Select Your Phone Model</p>
<select id="model" onchange="myFunction()">
<option value="0">
<option value="1">LG G7
<option value="2">LG G6
<option value="3">LG G5
<option value="4">LG Stylo 4+
<option value="5">LG Stylo 4
<option value="6">LG Stylo 3
<option value="7">LG Stylo 2
<option value="8">Other
</select>
</div>
<p class="sansserif" id="product"></p>
<div id=iphone-xs-max>
<p class="sansserif">
SCREEN: $80
<br>CHARGE PORT: $45
<br>HOME BUTTON: $50
<br>SPEAKER: $40
<br>BATTERY: $45
<br>FRONT CAMERA: $40
<br>REAR CAMERA: $70
</div>
<div id=iphone-xs>
<p class="sansserif">
SCREEN: $80
<br>CHARGE PORT: $45
<br>HOME BUTTON: $50
<br>SPEAKER: $40
<br>BATTERY: $45
<br>FRONT CAMERA: $40
<br>REAR CAMERA: $70
</div>
<div id=iphone-x>
<p class="sansserif">
SCREEN: $80
<br>CHARGE PORT: $45
<br>HOME BUTTON: $50
<br>SPEAKER: $40
<br>BATTERY: $45
<br>FRONT CAMERA: $40
<br>REAR CAMERA: $70
</div>
<div id=iphone-8+>
<p class="sansserif">
SCREEN: $80
<br>CHARGE PORT: $45
<br>HOME BUTTON: $50
<br>SPEAKER: $40
<br>BATTERY: $45
<br>FRONT CAMERA: $40
<br>REAR CAMERA: $70
</div>
<div id=iphone-8>
<p class="sansserif">
SCREEN: $80
<br>CHARGE PORT: $45
<br>HOME BUTTON: $50
<br>SPEAKER: $40
<br>BATTERY: $45
<br>FRONT CAMERA: $40
<br>REAR CAMERA: $70
</div>
<div id=iphone-7+>
<p class="sansserif">
SCREEN: $110
<br>CHARGE PORT: $60
<br>SPEAKER: $45
<br>BATTERY: $45
<br>FRONT CAMERA: $55
<br>REAR CAMERA: $115
</div>
<div id=iphone-7>
<p class="sansserif">
<br>SCREEN: $105
<br>CHARGE PORT: $45
<br>SPEAKER: $35
<br>BATTERY: $45
<br>REAR CAMERA: $55
</div>
<div id=iphone-6s+>
<p class="sansserif">
SCREEN: $80
<br>CHARGE PORT: $45
<br>HOME BUTTON: $50
<br>SPEAKER: $40
<br>BATTERY: $45
<br>FRONT CAMERA: $40
<br>REAR CAMERA: $70
</div>
<div id=iphone-6s>
<p class="sansserif">
<br>SCREEN: $75
<br>CHARGE PORT: $45
<br>HOME BUTTON: $40
<br>SPEAKER: $35
<br>BATTERY: $45
<br>CAMERA: $45
</div>
<div id=iphone-6+>
<p class="sansserif">
<br>SCREEN: $75
<br>CHARGE PORT: $48
<br>HOME BUTTON: $48
<br>SPEAKER: $35
<br>BATTERY: $45
<br>CAMERA: $45
</div>
<div id=iphone-6>
<p class="sansserif">
<br>SCREEN: $70
<br>CHARGE PORT: $40
<br>HOME BUTTON: $40
<br>SPEAKER: $35
<br>BATTERY: $45
<br>CAMERA: $40
</div>
<div id=iphone-5se>
<p class="sansserif">
<br>SCREEN: $70
<br>CHARGE PORT: $40
<br>HOME BUTTON: $40
<br>SPEAKER: $35
<br>BATTERY: $45
<br>CAMERA: $40
</div>
<div id=iphone-5s>
<p class="sansserif">
<br>SCREEN: $55
<br>CHARGE PORT: $35
<br>HOME BUTTON: $40
<br>SPEAKER: $35
<br>BATTERY: $40
<br>CAMERA: $40
</div>
<div id=iphone-5c>
<p class="sansserif">
<br>SCREEN: $55
<br>CHARGE PORT: $35
<br>HOME BUTTON: $35
<br>SPEAKER: $35
<br>BATTERY: $40
<br>CAMERA: $35
</div>
<div id=iphone-5>
<p class="sansserif">
<br>SCREEN: $55
<br>CHARGE PORT: $40
<br>HOME BUTTON: $35
<br>SPEAKER: $35
<br>BATTERY: $40
<br>CAMERA: $40
</div>
<script>
function myFunction() {
var x = document.getElementById("brand").value;
var c = document.getElementById("model").value
var a = document.getElementById("model1").value;
var b = document.getElementById("model2").value;
var d = document.getElementById("apple");
var e = document.getElementById("samsung");
var f = document.getElementById("lg");
var aa = document.getElementById("iphone-xs-max");
var ab = document.getElementById("iphone-xs");
var ac = document.getElementById("iphone-x");
var ad = document.getElementById("iphone-8+");
var ae = document.getElementById("iphone-8");
var af = document.getElementById("iphone-7+");
var ag = document.getElementById("iphone-7");
var ah = document.getElementById("iphone-6s+");
var ai = document.getElementById("iphone-6s");
var aj = document.getElementById("iphone-6+");
var ak = document.getElementById("iphone-6");
var al = document.getElementById("iphone-5se");
var am = document.getElementById("iphone-5s");
var an = document.getElementById("iphone-5c");
var ao = document.getElementById("iphone-5");
aa.style.display = "none";
ab.style.display = "none";
ac.style.display = "none";
ad.style.display = "none";
ae.style.display = "none";
af.style.display = "none";
ag.style.display = "none";
ah.style.display = "none";
ai.style.display = "none";
aj.style.display = "none";
ak.style.display = "none";
al.style.display = "none";
am.style.display = "none";
an.style.display = "none";
ao.style.display = "none";
d.style.display = "none";
e.style.display = "none";
f.style.display = "none";
if (x==1) {
d.style.display = "block";
if (a==1) {
aa.style.display = "block"
document.getElementById("product").innerHTML = "iPhone Xs Max";
}
if (a==2) {
ab.style.display = "block"
document.getElementById("product").innerHTML = "iPhone Xs";
}
if (a==3) {
ac.style.display = "block"
document.getElementById("product").innerHTML = "iPhone X";
}
if (a==4) {
ad.style.display = "block"
document.getElementById("product").innerHTML = "iPhone 8+";
}
if (a==5) {
ae.style.display = "block"
document.getElementById("product").innerHTML = "iPhone 8";
}
if (a==6) {
af.style.display = "block"
document.getElementById("product").innerHTML = "iPhone 7+";
}
if (a==7) {
ag.style.display = "block"
document.getElementById("product").innerHTML = "iPhone 7";
}
if (a==8) {
ah.style.display = "block"
document.getElementById("product").innerHTML = "iPhone 6s+"
;
}
if (a==9) {
ai.style.display = "block"
document.getElementById("product").innerHTML = "iPhone 6s";
}
if (a==10) {
aj.style.display = "block"
document.getElementById("demo").innerHTML = "iPhone 6+";
}
if (a==11) {
ak.style.display = "block"
document.getElementById("product").innerHTML = "iPhone 6";
}
if (a==12) {
al.style.display = "block"
document.getElementById("product").innerHTML = "iPhone 5SE";
}
if (a==13) {
am.style.display = "block"
document.getElementById("product").innerHTML = "iPhone 5s";
}
if (a==14) {
an.style.display = "block"
document.getElementById("product").innerHTML = "iPhone 5C";
}
if (a==15) {
ao.style.display = "block"
document.getElementById("product").innerHTML = "iPhone 5";
}
if (a==16) {
document.getElementById("product").innerHTML = "Please Contact Us!!";
}
}
if (x==2) {
e.style.display = "none";
document.getElementById("product").innerHTML = "Please Contact Us!!";
}
if (x==3) {
f.style.display = "none";
document.getElementById("product").innerHTML = "Please Contact Us!!";
}
if (x==4) {
document.getElementById("product").innerHTML = "Please Contact Us!!";
}
}
</script>
</body>
</html>
但是当我添加CSS时,整个过程就坏了。
使用CSS下拉
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
p.sansserif {
font-family: Arial, Helvetica, sans-serif;
}
.custom-select {
position: relative;
font-family: Arial, Helvetica, sans-serif;
}
.custom-select select {
display: none;
}
.select-selected {
background-color: Red;
}
.select-selected:after {
position: absolute;
content: "";
top: 14px;
right: 10px;
width: 0;
height: 0;
border: 6px solid transparent;
border-color: #fff transparent transparent transparent;
}
.select-selected.select-arrow-active:after {
border-color: transparent transparent #fff transparent;
top: 7px;
}
.select-items div,.select-selected {
color: white;
padding: 8px 16px;
border: 1px solid transparent;
border-color: transparent transparent rgba(0, 0, 0, 0.1) transparent;
cursor: pointer;
user-select: none;
}
.select-items {
position: absolute;
background-color: Red;
top: 100%;
left: 0;
right: 0;
z-index: 99;
}
.select-hide {
display: none;
}
.select-items div:hover, .same-as-selected {
background-color: rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body onload="myFunction()" text="white">
<div class="custom-select" style="width:200px;">
<select id="brand" onchange="myFunction()">
<option value="0">Select Brand
<option value="1">Apple
<option value="2">Samsung
<option value="3">LG
<option value="4">Other
</select>
</div>
<div id="apple" class="custom-select" style="width:200px;">
<select id="model1" onchange="myFunction()">
<option value="0">Select Model
<option value="1">iPhone Xs Max
<option value="2">iPhone Xs
<option value="3">iPhone X
<option value="4">iPhone 8+
<option value="5">iPhone 8
<option value="6">iPhone 7+
<option value="7">iPhone 7
<option value="8">iPhone 6s+
<option value="9">iPhone 6s
<option value="10">iPhone 6+
<option value="11">iPhone 6
<option value="12">iPhone 5SE
<option value="13">iPhone 5S
<option value="14">iPhone 5C
<option value="15">iPhone 5
<option value="16">Other
</select>
</div>
<div id="samsung" class="custom-select" style="width:200px;">
<select id="model2" onchange="myFunction()">
<option value="0">Select Model
<option value="1">Galaxy S9+
<option value="2">Galaxy S9
<option value="3">Galaxy S8+
<option value="4">Galaxy S8
<option value="5">Galaxy S7 Edge
<option value="6">Galaxy S7
<option value="7">Galaxy S6 Edge+
<option value="8">Galaxy S6 Edge
<option value="9">Galaxy S6
<option value="10">Note 9
<option value="11">Note 8
<option value="12">Note 7
<option value="13">Note 5
<option value="14">Other
</select>
</div>
<div id="lg" class="custom-select" style="width:200px;">
<select id="model" onchange="myFunction()">
<option value="0">Select Model
<option value="1">LG G7
<option value="2">LG G6
<option value="3">LG G5
<option value="4">LG Stylo 4+
<option value="5">LG Stylo 4
<option value="6">LG Stylo 3
<option value="7">LG Stylo 2
<option value="8">Other
</select>
</div>
<p class="sansserif" id="product"></p>
<div id=iphone-xs-max>
<p class="sansserif">
SCREEN: $80
<br>CHARGE PORT: $45
<br>HOME BUTTON: $50
<br>SPEAKER: $40
<br>BATTERY: $45
<br>FRONT CAMERA: $40
<br>REAR CAMERA: $70
</div>
<div id=iphone-xs>
<p class="sansserif">
SCREEN: $80
<br>CHARGE PORT: $45
<br>HOME BUTTON: $50
<br>SPEAKER: $40
<br>BATTERY: $45
<br>FRONT CAMERA: $40
<br>REAR CAMERA: $70
</div>
<div id=iphone-x>
<p class="sansserif">
SCREEN: $80
<br>CHARGE PORT: $45
<br>HOME BUTTON: $50
<br>SPEAKER: $40
<br>BATTERY: $45
<br>FRONT CAMERA: $40
<br>REAR CAMERA: $70
</div>
<div id=iphone-8+>
<p class="sansserif">
SCREEN: $80
<br>CHARGE PORT: $45
<br>HOME BUTTON: $50
<br>SPEAKER: $40
<br>BATTERY: $45
<br>FRONT CAMERA: $40
<br>REAR CAMERA: $70
</div>
<div id=iphone-8>
<p class="sansserif">
SCREEN: $80
<br>CHARGE PORT: $45
<br>HOME BUTTON: $50
<br>SPEAKER: $40
<br>BATTERY: $45
<br>FRONT CAMERA: $40
<br>REAR CAMERA: $70
</div>
<div id=iphone-7+>
<p class="sansserif">
SCREEN: $110
<br>CHARGE PORT: $60
<br>SPEAKER: $45
<br>BATTERY: $45
<br>FRONT CAMERA: $55
<br>REAR CAMERA: $115
</div>
<div id=iphone-7>
<p class="sansserif">
<br>SCREEN: $105
<br>CHARGE PORT: $45
<br>SPEAKER: $35
<br>BATTERY: $45
<br>REAR CAMERA: $55
</div>
<div id=iphone-6s+>
<p class="sansserif">
SCREEN: $80
<br>CHARGE PORT: $45
<br>HOME BUTTON: $50
<br>SPEAKER: $40
<br>BATTERY: $45
<br>FRONT CAMERA: $40
<br>REAR CAMERA: $70
</div>
<div id=iphone-6s>
<p class="sansserif">
<br>SCREEN: $75
<br>CHARGE PORT: $45
<br>HOME BUTTON: $40
<br>SPEAKER: $35
<br>BATTERY: $45
<br>CAMERA: $45
</div>
<div id=iphone-6+>
<p class="sansserif">
<br>SCREEN: $75
<br>CHARGE PORT: $48
<br>HOME BUTTON: $48
<br>SPEAKER: $35
<br>BATTERY: $45
<br>CAMERA: $45
</div>
<div id=iphone-6>
<p class="sansserif">
<br>SCREEN: $70
<br>CHARGE PORT: $40
<br>HOME BUTTON: $40
<br>SPEAKER: $35
<br>BATTERY: $45
<br>CAMERA: $40
</div>
<div id=iphone-5se>
<p class="sansserif">
<br>SCREEN: $70
<br>CHARGE PORT: $40
<br>HOME BUTTON: $40
<br>SPEAKER: $35
<br>BATTERY: $45
<br>CAMERA: $40
</div>
<div id=iphone-5s>
<p class="sansserif">
<br>SCREEN: $55
<br>CHARGE PORT: $35
<br>HOME BUTTON: $40
<br>SPEAKER: $35
<br>BATTERY: $40
<br>CAMERA: $40
</div>
<div id=iphone-5c>
<p class="sansserif">
<br>SCREEN: $55
<br>CHARGE PORT: $35
<br>HOME BUTTON: $35
<br>SPEAKER: $35
<br>BATTERY: $40
<br>CAMERA: $35
</div>
<div id=iphone-5>
<p class="sansserif">
<br>SCREEN: $55
<br>CHARGE PORT: $40
<br>HOME BUTTON: $35
<br>SPEAKER: $35
<br>BATTERY: $40
<br>CAMERA: $40
</div>
<script>
var x, i, j, selElmnt, a, b, c;
/*look for any elements with the class "custom-select":*/
x = document.getElementsByClassName("custom-select");
for (i = 0; i < x.length; i++) {
selElmnt = x[i].getElementsByTagName("select")[0];
/*for each element, create a new DIV that will act as the selected item:*/
a = document.createElement("DIV");
a.setAttribute("class", "select-selected");
a.innerHTML = selElmnt.options[selElmnt.selectedIndex].innerHTML;
x[i].appendChild(a);
/*for each element, create a new DIV that will contain the option list:*/
b = document.createElement("DIV");
b.setAttribute("class", "select-items select-hide");
for (j = 0; j < selElmnt.length; j++) {
/*for each option in the original select element,
create a new DIV that will act as an option item:*/
c = document.createElement("DIV");
c.innerHTML = selElmnt.options[j].innerHTML;
c.addEventListener("click", function(e) {
/*when an item is clicked, update the original select box,
and the selected item:*/
var y, i, k, s, h;
s = this.parentNode.parentNode.getElementsByTagName("select")[0];
h = this.parentNode.previousSibling;
for (i = 0; i < s.length; i++) {
if (s.options[i].innerHTML == this.innerHTML) {
s.selectedIndex = i;
h.innerHTML = this.innerHTML;
y = this.parentNode.getElementsByClassName("same-as-selected");
for (k = 0; k < y.length; k++) {
y[k].removeAttribute("class");
}
this.setAttribute("class", "same-as-selected");
break;
}
}
h.click();
});
b.appendChild(c);
}
x[i].appendChild(b);
a.addEventListener("click", function(e) {
/*when the select box is clicked, close any other select boxes,
and open/close the current select box:*/
e.stopPropagation();
closeAllSelect(this);
this.nextSibling.classList.toggle("select-hide");
this.classList.toggle("select-arrow-active");
});
}
function closeAllSelect(elmnt) {
/*a function that will close all select boxes in the document,
except the current select box:*/
var x, y, i, arrNo = [];
x = document.getElementsByClassName("select-items");
y = document.getElementsByClassName("select-selected");
for (i = 0; i < y.length; i++) {
if (elmnt == y[i]) {
arrNo.push(i)
} else {
y[i].classList.remove("select-arrow-active");
}
}
for (i = 0; i < x.length; i++) {
if (arrNo.indexOf(i)) {
x[i].classList.add("select-hide");
}
}
}
/*if the user clicks anywhere outside the select box,
then close all select boxes:*/
document.addEventListener("click", closeAllSelect);</script>
<script>
function myFunction() {
var x = document.getElementById("brand").value;
var c = document.getElementById("model").value
var a = document.getElementById("model1").value;
var b = document.getElementById("model2").value;
var d = document.getElementById("apple");
var e = document.getElementById("samsung");
var f = document.getElementById("lg");
var aa = document.getElementById("iphone-xs-max");
var ab = document.getElementById("iphone-xs");
var ac = document.getElementById("iphone-x");
var ad = document.getElementById("iphone-8+");
var ae = document.getElementById("iphone-8");
var af = document.getElementById("iphone-7+");
var ag = document.getElementById("iphone-7");
var ah = document.getElementById("iphone-6s+");
var ai = document.getElementById("iphone-6s");
var aj = document.getElementById("iphone-6+");
var ak = document.getElementById("iphone-6");
var al = document.getElementById("iphone-5se");
var am = document.getElementById("iphone-5s");
var an = document.getElementById("iphone-5c");
var ao = document.getElementById("iphone-5");
aa.style.display = "none";
ab.style.display = "none";
ac.style.display = "none";
ad.style.display = "none";
ae.style.display = "none";
af.style.display = "none";
ag.style.display = "none";
ah.style.display = "none";
ai.style.display = "none";
aj.style.display = "none";
ak.style.display = "none";
al.style.display = "none";
am.style.display = "none";
an.style.display = "none";
ao.style.display = "none";
d.style.display = "none";
e.style.display = "none";
f.style.display = "none";
if (x==1) {
d.style.display = "block";
if (a==1) {
aa.style.display = "block"
document.getElementById("product").innerHTML = "iPhone Xs Max";
}
if (a==2) {
ab.style.display = "block"
document.getElementById("product").innerHTML = "iPhone Xs";
}
if (a==3) {
ac.style.display = "block"
document.getElementById("product").innerHTML = "iPhone X";
}
if (a==4) {
ad.style.display = "block"
document.getElementById("product").innerHTML = "iPhone 8+";
}
if (a==5) {
ae.style.display = "block"
document.getElementById("product").innerHTML = "iPhone 8";
}
if (a==6) {
af.style.display = "block"
document.getElementById("product").innerHTML = "iPhone 7+";
}
if (a==7) {
ag.style.display = "block"
document.getElementById("product").innerHTML = "iPhone 7";
}
if (a==8) {
ah.style.display = "block"
document.getElementById("product").innerHTML = "iPhone 6s+"
;
}
if (a==9) {
ai.style.display = "block"
document.getElementById("product").innerHTML = "iPhone 6s";
}
if (a==10) {
aj.style.display = "block"
document.getElementById("demo").innerHTML = "iPhone 6+";
}
if (a==11) {
ak.style.display = "block"
document.getElementById("product").innerHTML = "iPhone 6";
}
if (a==12) {
al.style.display = "block"
document.getElementById("product").innerHTML = "iPhone 5SE";
}
if (a==13) {
am.style.display = "block"
document.getElementById("product").innerHTML = "iPhone 5s";
}
if (a==14) {
an.style.display = "block"
document.getElementById("product").innerHTML = "iPhone 5C";
}
if (a==15) {
ao.style.display = "block"
document.getElementById("product").innerHTML = "iPhone 5";
}
if (a==16) {
document.getElementById("product").innerHTML = "Please Contact Us!!";
}
}
if (x==2) {
e.style.display = "none";
document.getElementById("product").innerHTML = "Please Contact Us!!";
}
if (x==3) {
f.style.display = "none";
document.getElementById("product").innerHTML = "Please Contact Us!!";
}
if (x==4) {
document.getElementById("product").innerHTML = "Please Contact Us!!";
}
}
</script>
</body>
</html>
已经有一段时间了,因为我已经完成了这些工作,这对我来说有点模糊,我不知道可能出什么问题了。不幸的是,所有这些都必须放在一个字符串中,因为它要进入HTML模块,并且不能从其他文件中提取。
在此先感谢您的帮助。