当我添加按钮的行以在HTML中启用时钟并在<script>
标签中添加受尊重的功能时(顺便说一下可能会或可能不会),那么该页面上的所有功能都是未定义。我在该页面上只有一个其他功能,所以它可能就是这样。我已经找了一段时间用于语法问题,但我找不到任何东西。
JavaScript,然后是CSS,然后是页面的HTML。
function startTime() {
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
m = checkTime(m);
s = checkTime(s);
document.getElementById('txt').innerHTML =
h + ":" + m + ":" + s;
var t = setTimeout(startTime, 500);
}
function checkTime(i) {
if (i < 10) {i = "0" + i};
return i;
}
.headtitle {
color:red;
font-family: "Courier New", Courier, monospace;
display: flex;
flex-wrap: wrap;
justify-content: center;
border: 5px solid #00f;
padding: 10px;
}
.subtitle{
display: flex;
flex-wrap: wrap;
justify-content: center;
font-size: 1.25rem
}
a.firstlink{
word-spacing: 30px;
}
a:visited{
color:lightblue
}
body{
background-image: url("http://i.kinja-img.com/gawker-media/image/upload/a942qcqwrcmveiq37zli.png");
background-repeat:repeat;
color: white;
}
.list{
display: inline;
}
.list li{
display: inline;
padding-left: 1.5rem;
}
.button{
float:right;
border: 1px solid #f00;
padding: 5px
}
.button:active{
position: relative;
top: 2px;
left: 2px;
}
.JavascriptButton{
float:right;
}
.clickText{
cursor:pointer;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="Website task.css">
<script type="text/javascript" src="new 1.js"></script>
<script type="text/javascript">
function openFunction() {
window.open('Website Task.html', '_blank');
}
function showTime() {
document.getElementByID("currentTime").innerhtml = "The time is now" startTime();
}
</script>
<title>Javascript page</title>
</head>
<body>
<div class="header">
<h1 class="headtitle">Javascript demo page</h1>
<p class="subtitle">This page is for demonstrating functions in Javascript in particular, as well as jQuery.</p>
<p id="currentTime"></p>
<button onclick="showTime()">Click here to show the time</button>
<p></p>
<a class="clickText" onclick="openFunction()">Click this text to return to the previous page in a new window</a>
<button class="JavascriptButton" onclick="window.location='Website Task.html';">Previous page</button>
</div>
</body>
</html>
答案 0 :(得分:1)
您的代码中存在语法错误。只需打开开发工具即可找到它......
document.getElementById("currentTime").innerhtml = "The time is now" startTime();
=&GT; "the time is now " + startTime();
但是你的startTime函数没有返回任何东西,所以它就像那样没用了