Artikel ini menjelaskan metode JS untuk mencapai perubahan warna latar belakang halaman web dan warna di kotak pilih pada saat yang sama. Bagikan untuk referensi Anda. Metode implementasi spesifik adalah sebagai berikut:
Salin kode sebagai berikut: <! Doctype html public "-// w3c // dtd xhtml 1.0 transisi // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "konten-tipe" content = "text /html; charset = gb2312" />
<Title> JS mengimplementasikan warna latar belakang halaman web dan warna di kotak pilih pada saat yang sama </iteme>
</head>
<body>
<bahasa skrip = "javascript">
colors = array baru ('#fffffff', '#ffccff', '#ff99ff', '#ff66ff', '#ff33ff', '#ff00ff', '#fffcc', 'ffccccc', '#ff99cc', 'ff66cc'#'ff3', 'ff3', 'ff3', 'ff3', 'ff3', 'ff3', 'ff3', 'ff3', 'ff3, , '#Ffcc99', '#ff9999', '#ff6699', '#ff3399', '#ff0099', '#fff66', '#ffcc6 6 ','#ff9966 ','#ff6666 ','#ff3366 ','#ff0066 ','#fff33 ','#ffcc33 ','#fff 9933 ','#ff6633 ','#ff3333 ','#ff0033 ','#ffff00 ','#ffcc00 ','#ff9900 ','#ff6600 ','#ff3300 ',' ff0000 ',' ccffff ',', ',' CCFF9 ',' CCFF9 ',' CCFF9 ',' CCFF9 ',' CCFF9 ',' CCFF9 ',' CCFF9 ',' CCFF9 ',' CCFF9, , '#Cc33ff', '#cc00ff', '#ccffcc', '#cccccc', '#cc99cc', '#cc66cc', '#cc33cc ','#Cc00cc ','#ccff99 ','#cc9999 ','#cc9999 ','#cc6699 ','#cc3399 ','#cc00cc 099 ','#ccff66 ','#cccc66 ','#cc9966 ','#cc6666 ','#cc3366 ','#cc0066 ','#cc006 6 ','#ccff33 ','#cc333 ','#cc9933 ','#cc6633 ','#cc3333 ','#cc0033 ','#ccff00 ', '#Cccc00', '#cc9900', '#cc6600', '#cc3300', '#cc0000', '#99ffff', '#99ccff', '#9999ff', '#9966FF', '#9933FF', '999FF', '99, '99,' 999, '999,' 999, '999F', '999F', '999F', '999F', '999F', '999F', '999F', '999F', '999F', '999F', '999F', '999F', '999F', '999F', '999F', '999F', '99 Cc ','#9966cc ','#9933cc ','#9900cc ','#99ff99 ','#99cc99 ','#999999 ','#996699 ','#993399 ','#990099 ','#99ff66 ','#99cc66 ','#999966 ','#996666 ','#996666 ',' #993366 ','#990066 ','#99ff33 ','#99cc33 ','#999933 ','#996633 ','#993333 ' , '#990033', '#99ff00', '#99cc00', '#999900', '#996600', '#993300', '#99000 0 ','#66ffff ','#66ccff ','#6699ff ','#6666ff ','#6633ff ','#6600ff ','#66ffcc ','#66ccc ',' 6699cc ','#6666cc ',' 66ccc ',' 6699, '666cc', '6633,' 6633, '663,' 663, '663,' 663, 66cc99 ','#669999 ','#666699 ','#663399 ','#660099 ','#66ff66 ','#66cc66 ', '#669966', '#666666', '#663366', '#660066', '#66ff33', '#66cc33', '#669933 ','#666633 ','#66333 ','#660033 ','#66ff00 ','#66cc00 ','#669900 ','#666600 ',' #663300 ','#660000 ','#33ffff ','#33ccff ','#3399ff ','#3366ff ','#3366ff ','#33 333ff ','#3300ff ','#33ffcc ','#33cccc ','#3399cc ','#3366cc ','#3333cc ','#3300c C ','#33ff99 ','#33cc99 ','#339999 ','#336699 ','#3333999 ','#33333999 ','#330099 ' , '#33ff66', '#33cc66', '#339966', '#336666', '#333366', '#330066', '#33ff3 3 ','#33CC33 ','#339933 ','#336633 ','#333333 ','#330033 ','#33ff00 ','#3333 CC00','#339900','#336600','#3333000','#330000','#00FFFF','#00CCFF','#0099FF','#0066FF','#0033FF','#0000FF','#00FFCC','#00CCCC','#0099CC', '#0066cc', '#0033cc', '#0000cc', '#00ff99', '#00cc99', '#009999', '#006699 ','#003399 ','#0000999 ','#00ff66 ','#00cc66 ','#009966 ','#006666 ','#003 366 ','#000066 ','#00FF33 ','#00cc33 ','#009933 ','#006633 ','#003333 ','#0 00033 ','#00ff00 ','#00cc00 ','#009900 ','#006600 ','#003300 ','#000000 ');
function show (file) {
var url = file.options [file.selectectedIndex] .value;
if (document.all || document.layers)
location.href = url;
lain if (document.geteLementById) {
if (url! = tidak terdefinisi)
location.href = url;
}
}
kekuatan var;
var color1 = warna [math.round (math.random () * (colors.length-1))];
var color2 = color [math.round (math.random () * (colors.length-1))];
var color3 = colors [math.round (math.random () * (colors.length-1))];
kekuatan = '<style type = "text/css"> pilih {width: 300; Tinggi: 118; meluap: tersembunyi; Font-Family: Times New Roman; Ukuran font: 14px; warna:';
kekuatan += warna1;
kekuatan += '; latar belakang:';
kekuatan += warna2;
kekuatan += ';} body {latar belakang:';
kekuatan += warna3;
kekuatan += ';} td {font-family: Times New Roman; Ukuran font: 14px; Warna: #000000;} </style> ';
Document.writeln (Streng);
</script>
<tabel cellpacing = "0" cellPadding = "0">
<Form name = "Form" target = "_ blank">
<tr>
<td>
<Pilih name = "showoff" id = "showoff" size = "3" onchange = "show (document.form.showoff)">
<Option value = "http://www.163.com"> 163 NetEase </pection>
<Option value = "http://www.baidu.com"> Baidu Search </pection>
</pilih>
</td>
</tr>
</form>
</boable>
</body>
</html>
Saya harap artikel ini akan membantu pemrograman JavaScript semua orang.