У меня возникли проблемы с работой моих функций, и моя книга, похоже, просто мусор. Я уверен, что ошибка чисто синтаксическая, хотя может быть и более.
Вот JavaScript, который я написал. Очевидно, что функция баннера не обеспечивает полную функциональность, но она должна делать что-то. В настоящее время я просто получаю ссылку на неработающее изображение.
function displayBanner(currentDate) {
var imgSrc = defaultLogo;
if (currentDate.getMonth() == 1)
imgSrc = "winterLogo";
return ("<img src='" + imgSrc + ".gif'>");
}
function calcDaysToSale(currentDate) {
var saleDay = new Date();
saleDay.setDate(15); // sets the sale date to the 15th of the current month
// Subtracts the days remaining until the sale.
// If the number is negative, the sale is over.
var Days = saleDay.getDate()-currentDate.getDate();
if (Days < 0) {
return "The sale has ended.";
}
else {
return Days;
}
}
Теперь я думаю, что причина этого в том, что он не вызывается правильно. Вот функция, встроенная в заголовок html-страницы:
<script type="text/javascript" src="flowers.js"></script>
<script type="text/javascript">
function pageSetup() {
var today = new Date(); // this creates a date object with today's date
var banner = displayBanner(today); // *should* call the displayBanner function
var days = calcDaysToSale(today); // *should* call the function using today's date
document.sale.saleMessage.value = days; // *should* set the value to days.
// Obviously none of it works.
}
</script>
Я звоню pageSetup()
внизу моей страницы. Я разместил полный HTML-код ниже.
Это может быть, и я почти уверен, что это чисто синтаксическая проблема. Однако то, что я подумал о Google и посмотрел в своей книге, не привело меня к каким-либо ответам.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Carol's Flowers</title>
<link href="flowers.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="flowers.js"></script>
<script type="text/javascript">
function pageSetup() {
var today = new Date(); // this creates a date object with today's date
var banner = displayBanner(today); // *should* call the displayBanner function
var days = calcDaysToSale(today); // *should* call the function using today's date
document.sale.saleMessage.value = days; // *should* set the value to days.
// Obviously none of it works.
}
</script>
</head>
<body class="oneColLiqCtrHdr">
<div id="container">
<div id="header">
<p><img name="myBanner" src="banner" id="myBanner" alt="Carol's Flowers" />
<!-- end #header -->
</p>
<div id="links"><a href="#">Home</a> | <a href="#">General Arrangements</a> | <a href="#">Seasonal Designs</a> | <a href="#">Custom Orders</a> | <a href="#">Location</a></div>
</div>
<div id="mainContent">
<table id="mainTable">
<tr>
<td width="201"><h1><img src="Flowers.JPG" alt="Random Flowers" width="200" height="255" /></h1></td>
<td width="687">
<p>Here at Carol's Flowers, we believe that there is a perfect floral arrangment for every occasion! Take a look around and see if there is anything you like. If we don't already have it, then we will create it for you!</p></td>
</script>
</tr>
</table>
<!-- end #mainContent --></div>
<div id="footer">
<p> <form name="sale" id="sale">
Days Until Mid Month Madness Sale :
<input type="text" name="saleMessage" id="saleMessage" /></form></p>
<!-- end #footer --></div>
<!-- end #container --></div>
<!-- I am trying to run the script here -->
<script type="text/javascript">
pageSetup();
</script>
</body>
</html>