以下是显示浏览器详细信息的 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/