我已经处理过一个简单的JS / HTML工作,我在使用document.body.innerHTML在JS中显示一个html代码时出现问题,这里是代码:
plz help,tha
let html;
let rday;
rday = new Date();
let day;
day = rday.getDay();
let date;
date = rday.getDate();
let month;
month = rday.getMonth();
let year;
year = rday.getFULLYear();
html =`
<P> <span> ${day} </span>
<span> ${month}/ </span>
<span> ${date}/ </span>
<span> ${year} </span> </p>
`;
console.log(html);
document.body.innerHTML = hmtl;
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script type="text/javascript" src="javascript.js">
</script>
</body>
</html>
你可以看到我尝试了控制台,但问题是什么?这是pic:enter image description here
您的代码中存在一些语法错误。
.getFULLYear()
这是不正确的,应该是.getFullYear()
https://www.w3schools.com/jsref/jsref_getfullyear.asphtml
let html;
let rday;
rday = new Date();
let day;
day = rday.getDay();
let date;
date = rday.getDate();
let month;
month = rday.getMonth();
let year;
year = rday.getFullYear(); // <- incorrect function call
html =`
<P> <span> ${day} </span>
<span> ${month}/ </span>
<span> ${date}/ </span>
<span> ${year} </span> </p>
`;
console.log(html);
document.body.innerHTML = html; // <- you spelt html wrong
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script type="text/javascript" src="javascript.js">
</script>
</body>
</html>