gpt4 book ai didi

javascript不会执行但会打印代码

转载 作者:行者123 更新时间:2023-11-28 12:32:48 24 4
gpt4 key购买 nike

我有一些 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>

提前致谢!丹多18

最佳答案

关闭其中一个 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

此外,还可以使用数组而不是像 switch 这样的开关来简化该功能

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];
}

关于javascript不会执行但会打印代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20485151/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com