javascript - 在javascript中显示日期

标签 javascript html

尝试自学 JavaScript。但是,我无法弄清楚为什么以下代码不起作用。有什么想法吗?

<!DOCTYPE html>
<html>
    <body>

    <p> Click the button to display the date</p>

    <button onclick="showDate()">HIT ME</button>

    <script>
        function displayDate()
        {
          document.getElementById("test").innterHTML=displayDate();   
        }
    </script>

    <p id="test"></p>
</body>

复制粘贴错误,以下是实际代码:

<!DOCTYPE html>
<html>
    <body>

    <p> Click the button to display the date</p>

    <button onclick="showDate()">HIT ME</button>

    <script>
        function showDate()
        {
          document.getElementById("test").innterHTML=Date();   
        }
    </script>

    <p id="test"></p>
</body>

最佳答案

document.getElementById("test").innterHTML=Date();   

应该是

document.getElementById("test").innerHTML=Date();   

关于javascript - 在javascript中显示日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22620663/

相关文章:

javascript - 使用 .match 和 .search 的区别

javascript - 即使在 AngularJS 中使用 ng-cloak,页脚模板也会闪烁

html - 如何在不拉伸(stretch)的情况下将图像放入圆圈中?

css - margin : 0 auto ;不居中内容

html - HTML5 AppCache 和普通浏览器缓存有什么区别?

html - 在@media 屏幕上将参数传递给服务器

javascript - Google Sign In 无法识别 Angular 中的回调函数

javascript - Threejs - 几何坐标系到屏幕坐标系

javascript - RESTful API 中复杂的 POST 参数的可能格式是什么?

html - 从顶部在同一水平线的同一行中显示两个 div