Javascript Navigator Cookie 测试不起作用

标签 javascript html navigator

我正在尝试使用Javascript Navigator对象来测试浏览器中是否启用了cookie。我使用以下代码,按钮显示,但单击后不显示消息。

  <!DOCTYPE html>
    <html>
    <body>
    <p> Are cookies enabled ? </p>
    <button onclick="myFunction()"> Button1 </button>
    <p id="para1"></p>
    <script>
    function myFunction()
    {
    document.getElementbyId("para1").innerHTML="Cookies enabled is "+ navigator.cookieEnabled;
    }
    </script>
    </body>
    </html>

最佳答案

方法是.getElementById() ,而不是 .getElementbyId()。如果您打开浏览器的控制台,您会看到类似以下内容的内容:

TypeError: document.getElementbyId is not a function

http://jsbin.com/kixatozafu/1/edit

  <!DOCTYPE html>
    <html>
    <body>
    <p> Are cookies enabled ? </p>
    <button onclick="myFunction()"> Button1 </button>
    <p id="para1"></p>
    <script>
    function myFunction()
    {
    document.getElementById("para1").innerHTML="Cookies enabled is "+ navigator.cookieEnabled;
    }
    </script>
    </body>
    </html>

关于Javascript Navigator Cookie 测试不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30148648/

相关文章:

javascript - 如何水平居中比手机屏幕宽的div?

javascript - "Navigator is not defined"JSHint,带有 JSON 的预测 API

javascript - 地理位置自定义更新间隔(30 秒)

google-chrome - 是否可以在 WebRtc 中组合媒体轨道/流

javascript - "this"javascript 回调函数中的关键字

javascript - getElementsByTagName 不适用于每个标签

html - CSS - 定位多个相邻的 div 以在 2 个 div 之间堆叠一个

javascript - CSS3卡片翻转动画,不支持时检测

javascript - Google Apps 脚本查找函数来电者 ID

javascript - 用于根据其 html 内容禁用链接的 jQuery