将毫秒添加到时钟时出现 JavaScript 错误消息 [英] JavaScript Error Message when adding Milliseconds to a clock
本文介绍了将毫秒添加到时钟时出现 JavaScript 错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不断收到此错误消息:
I keep getting this error message:
未捕获的语法错误:意外的标识符
Uncaught SyntaxError: Unexpected identifier
为时钟添加毫秒时.我是从书上抄来的,所以我不确定有什么问题.
when adding milliseconds to a clock. I am copying it out of a book, so I am not sure what is wrong.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN">
<html>
<head>
<title>Event Test</title>
</head>
<body>
<h1>Event Test</h1>
<script type="text/javascript">
now = new Date();
localtime = now.toString();
utctime = now.toGMTString();
document.write("<strong>Local time:</strong> "
+ localtime + "<br/>");
document.write("<strong>UTC time:</strong> " +
utctime);
hours = now.getHours();
minutes = now.getMinutes();
seconds = now.getSeconds();
mil = now.getMilliseconds();
document.write("<h1>");
document.write(hours + ":" + minutes + ":" + seconds + ":" mil);
document.write("</h1>");
</script>
</body>
</html>
推荐答案
看起来你在这里缺少一个 +
:
Looks like you're missing a +
here:
document.write(hours + ":" + minutes + ":" + seconds + ":" mil);
//--------------------------------------------------------^^^^
这篇关于将毫秒添加到时钟时出现 JavaScript 错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文