我有一些HTML代码,其中javascript代码而不是执行它只显示javascript代码。这可能是一个简单的问题或愚蠢的错误,但在搜索一些网站后,我似乎无法找到答案
我的代码:
<!DOCTYPE html>
<html>
<head>
<title>Daniel's Quicky Links</title>
<style type="text/css">
a {
text-decoration:none;
color:blue;
}
div.author {
font-size:12px;
text-align:center;
position:absolute;
bottom:0%;
width:98%;
margin-left:auto;
margin-right:auto;
}
</style>
</head>
<body>
<p id="date"><button onClick="printDay()">day</button></p>
<table border="3" cellpadding="5" cellspacing="0" summary="This is a list of links to help you quickly guide through the internet" width="40%">
<caption>This is a list of links to help you quickly guide through the internet</caption>
<tr>
<th>Link</th>
<th>Use</th>
</tr>
<tr>
<td><a href="http://google.com" target="_blank">Google</a></td>
<td>This link is to a great search engine</td>
</tr>
<tr>
<td><a href="http://facebook.com" target="_blank">Facebook</a></td>
<td>This link is to a great social media outlet</td>
</tr>
<tr>
<td><a href="http://wikipedia.org" target="_blank">Wikipedia</a></td>
<td>This link is to a great wiki containing information on plenty of topics</td>
</tr>
<tr>
<td><a href="http://ask.com" target="_blank">Ask</a></td>
<td>This link is to a great forum you can ask questions</td>
</tr>
</table>
<div class="author"><p>
<hr width="101%">
Author: ********</br>
Version: 0.1</br>
Contact: <a href="mailto:*********?Subject=Quicky Links complaint,suggestion,comment&Body=My thoughts on Quicky Links">************</a>
</p></div
<script type="text/javascript">
function printDay()
{
var x = new String("");
var day=new Date().getDay();
switch(day)
{
case 0:
x="Today is Sunday";
break;
case 1:
x="Today is Monday";
break;
case 2:
x="Today is Tuesday";
break;
case 3:
x="Today is Wednesday";
break;
case 4:
x="Today is Thursday";
break;
case 5:
x="Today is Friday";
break;
case 6:
x="Today is Saturday";
break;
default:
x="Day does not exist";
}
document.getElementById("date").innerHTML=x;
}
</script>
</body>
</html>
提前致谢! Dando18
答案 0 :(得分:4)
关闭其中一个div
时出现语法错误<div class="author"><p>
<hr width="101%">
Author: *********</br>
Version: 0.1</br>
Contact: <a href="mailto:************?Subject=Quicky Links complaint,suggestion,comment&Body=My thoughts on Quicky Links">**********</a>
</p></div> //<-- here the > is missing after </div
此外,可以使用数组而不是像
这样的开关来简化该功能var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
function printDay() {
var day = new Date().getDay();
//the default text is not required since the day value will be within the range 0-6
document.getElementById("date").innerHTML = 'Today is ' + days[day];
}
答案 1 :(得分:2)
您有一个开放的<div> tag right before your opening
标记。这会导致两者合并并被忽略为无效。因此,您的JavaScript不仅仅是纯文本内容:
</p></div
<script type="text/javascript">
答案 2 :(得分:0)
你必须关闭html标签
replace </p></div with </p></div>