Javascript 请告诉我这个简单的代码有什么问题
我是html新手。我试图争取时间,但代码在浏览器中不起作用。请帮忙Javascript 请告诉我这个简单的代码有什么问题,javascript,html,Javascript,Html,我是html新手。我试图争取时间,但代码在浏览器中不起作用。请帮忙 <h1>My First JavaScript</h1> <button type="button" onclick="document.getElementByid('time').innerHTML = Date()"> Click me to display Date and Time.</button> <p id="time"></p> &
<h1>My First JavaScript</h1>
<button type="button"
onclick="document.getElementByid('time').innerHTML = Date()">
Click me to display Date and Time.</button>
<p id="time"></p>
</body>
</html>
在代码中输入错误
<h1>My First JavaScript</h1>
<button type="button"
onclick="document.getElementByid('time').innerHTML = Date()">
Click me to display Date and Time.</button>
<p id="time"></p>
</body>
</html>
document.getElementByid('time')
应该是:
<h1>My First JavaScript</h1>
<button type="button"
onclick="document.getElementByid('time').innerHTML = Date()">
Click me to display Date and Time.</button>
<p id="time"></p>
</body>
</html>
document.getElementById('time')
document.getElementById('time')
你错过了我的首都
<h1>My First JavaScript</h1>
<button type="button"
onclick="document.getElementByid('time').innerHTML = Date()">
Click me to display Date and Time.</button>
<p id="time"></p>
</body>
</html>
对于这样的简单调试,您可以使用web浏览器的控制台。只需点击F12,并查看控制台,错误将在此处描述。此处有一个输入错误:
<h1>My First JavaScript</h1>
<button type="button"
onclick="document.getElementByid('time').innerHTML = Date()">
Click me to display Date and Time.</button>
<p id="time"></p>
</body>
</html>
document.getElementByid
应该是
<h1>My First JavaScript</h1>
<button type="button"
onclick="document.getElementByid('time').innerHTML = Date()">
Click me to display Date and Time.</button>
<p id="time"></p>
</body>
</html>
document.getElementById
工作示例。请修复该行:
<h1>My First JavaScript</h1>
<button type="button"
onclick="document.getElementByid('time').innerHTML = Date()">
Click me to display Date and Time.</button>
<p id="time"></p>
</body>
</html>
document.getElementByid('time')
并将其更改为
<h1>My First JavaScript</h1>
<button type="button"
onclick="document.getElementByid('time').innerHTML = Date()">
Click me to display Date and Time.</button>
<p id="time"></p>
</body>
</html>
getElementById拼写错误请更改下一行:
<h1>My First JavaScript</h1>
<button type="button"
onclick="document.getElementByid('time').innerHTML = Date()">
Click me to display Date and Time.</button>
<p id="time"></p>
</body>
</html>
document.getElementByid'time'
<h1>My First JavaScript</h1>
<button type="button"
onclick="document.getElementByid('time').innerHTML = Date()">
Click me to display Date and Time.</button>
<p id="time"></p>
</body>
</html>
致:
<h1>My First JavaScript</h1>
<button type="button"
onclick="document.getElementByid('time').innerHTML = Date()">
Click me to display Date and Time.</button>
<p id="time"></p>
</body>
</html>
document.getElementById'time'
<h1>My First JavaScript</h1>
<button type="button"
onclick="document.getElementByid('time').innerHTML = Date()">
Click me to display Date and Time.</button>
<p id="time"></p>
</body>
</html>
检查一下你的控制台12就是方法。按下后,转到控制台选项卡