【发布时间】:2016-01-14 14:55:25
【问题描述】:
链接到 JSfiddle: http://jsfiddle.net/HappyHands31/LnbzgL14/
我真的很接近让它发挥作用。现在它只工作了一半。例如,当我单击“冒险”时,正文变为蓝色,但我需要所有超链接也变为蓝色。浪漫是红色,放松是绿色,家庭是棕色。我是否需要以某种方式将 colorLinks 函数放入 change_color 函数中?让我知道是否需要进一步澄清。谢谢!
HTML:
<!DOCTYPE html>
<html>
<head>
<title>Castaway Vacations, LLC</title>
</head>
<body leftmargin=0 rightmargin=0 bgcolor=#ffcc99 text=#993300 link=#993300 vlink=#996633>
<br>
<table width=100% border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=95% align="right" bgcolor=#ffffff>
<img src="castaway_logo.jpg">
<br>
<font face=arial>Vacations, LLC</font></td>
<td bgcolor=#ffffff> </td>
</tr>
</table>
<br>
<br>
<div align="center">
<table width=600>
<tr>
<td width=300 valign="top">
<font face=arial size=3><b><i>Select Mood...</i></b></font>
<br>
<br>
<font face=arial>
<a style="text-decoration:none" id="one" href="#">Romantic</a>
<br><br>
<a style="text-decoration:none" id="two" href="#">Adventure</a>
<br><br>
<a style="text-decoration:none" id="three" href="#">Relaxation</a>
<br><br>
<a style="text-decoration:none" id="four" href="#">Family</a><br>
<br><br>
<br>
<a style="text-decoration:none" id="reqBrochure" href="#">
Request Brochure...</a>
</font>
</td>
<td align="center"><img id="original.jpg" src="orig_main.jpg">
<br>
<i>Your Vacation Awaits!
</tr>
</center>
<script src="castaway.js"></script>
</body>
</html>
</DOCTYPE>
Javascript:
document.getElementById('one').addEventListener('click', change_color);
document.getElementById('two').addEventListener('click', change_color2);
document.getElementById('three').addEventListener('click', change_color3);
document.getElementById('four').addEventListener('click', change_color4);
document.getElementById('reqBrochure').addEventListener('click',
openWindow);
function change_color() {
document.body.style.color = "red";
document.body.style.background = "purple";
document.getElementById("original.jpg").src = "rom_main.jpg";
}
function change_color2() {
document.body.style.color = "blue";
document.body.style.background = "orange";
document.getElementById("original.jpg").src = "adv_main.jpg";
}
function change_color3() {
document.body.style.color = "green";
document.body.style.background = "#47D1FF";
document.getElementById("original.jpg").src = "rel_main.jpg";
}
function change_color4() {
document.body.style.color = "brown";
document.body.style.background = "black";
document.getElementById("original.jpg").src = "fam_main.jpg";
}
colorLinks("red");
function colorLinks(color) {
var links = document.getElementsByTagName("a");
for (var i = 0; i < links.length; i++) {
if (links[i].href) {
links[i].style.color = color;
}
}
}
//pop-up form window;
var win; // makes variable global;
function openWindow() {
win = window.open("form.html", "form", "width=400,height=350");
}
function closeWindow() {
win.close();
var openLink = document.getElementById('reqBrochure');
openLink.innerHTML = "Request Submitted";
}
忽略弹出表单窗口的脚本,除非您认为这与它无法正常工作的原因有关。谢谢!
【问题讨论】:
标签: javascript jquery html function hyperlink