JavaScript没有显示在网页上? [英] JavaScript doesn't show on webpage?

查看:117
本文介绍了JavaScript没有显示在网页上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<!DOCTYPE html>

<head>
<title>Cookie Clicker</title>
 </head>

 <body>
 <div id="JS"></div>


<script>
var cookies = 0;

function addCookies(){
    cookies += 1;
    getElementById("JS").innerHTML="Cookies: " + cookies;
}
 getElementById("JS").innerHTML="Cookies: " + cookies;

</script>

<button onclick='addCookies()'>Add Cookies</button>

</body>

</html>

addCookies()不起作用。它应该在浏览器中说 Cookies:变量 cookies 。有人可以向我解释一下吗?它在浏览器中显示的只是按钮。

The addCookies() doesn't work. It is supposed to say in the browser Cookies: variablecookies. Could someone explain it to me? All it shows in the browser is the button.

推荐答案

没有 getElementById 本机javascript中的功能。使用 document.getElementById 方法。

There is no getElementById function in native javascript. Use document.getElementById method.

这篇关于JavaScript没有显示在网页上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆