javascript - 元素不更新内容

标签 javascript html navigator

以下是显示浏览器详细信息的 JavaScript 代码。它没有显示输出。请让我知道我哪里做错了。

<html>
<head>
    <title></title>
    <script type="text/javascript">

        var txt;
        txt = "<p>Browser CodeName: " + navigator.appCodeName + "</p>";
        txt+= "<p>Browser Name: " + navigator.appName + "</p>";
        txt+= "<p>Browser Version: " + navigator.appVersion + "</p>";
        txt+= "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>";
        txt+= "<p>Platform: " + navigator.platform + "</p>";
        txt+= "<p>User-agent header: " + navigator.userAgent + "</p>";

        document.getElementById("example").innerHTML=txt;

      </script>
</head>

<body>
    <p id="example"></p>
</body>
</html>

最佳答案

您在 example div 元素存在之前运行 Javascript。稍后运行(= 在文档末尾)。

关于javascript - 元素不更新内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9248865/

相关文章:

javascript - 正则表达式 JavaScript

javascript - 我可以在不分配变量的情况下返回 else/if 语句的答案吗?

javascript - AngularJS:指令未触发或工作

javascript - 需要访问 React Native 中底部选项卡导航器中的状态以实现购物车徽章

javascript - 在 PhantomJS 和 Python 中伪造 Flash 插件信息

dart - 尝试调用 : ancestorStateOfType(Instance of 'TypeMatcher<NavigatorState>'

javascript - 如何将实时数据输入NextJS?

javascript - 意外的 token 导入 - Electron/React

html - 带 srcdoc 的 iframe : same-page links load the parent page in the frame

android - 触发键盘时CSS隐藏布局的底部