小编Dee*_*C P的帖子

把脚本放在头部和身体之间有什么区别?

我遇到了问题.

<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <script type="text/javascript">
  alert(document.getElementsByTagName("li").length); 
  </script>
  <title>purchase list</title>
</head>
<body>
  <h1>What to buy</h1>
  <ul id="purchases">
    <li> beans</li>
    <li>Cheese</li>
  </ul>
</body>
Run Code Online (Sandbox Code Playgroud)

当我把脚本放在头部时,结果显示为0

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
                      "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Shopping list</title>
</head>
<body>
  <h1>What to buy</h1>

  <ul id="purchases">
    <li>Cheese</li> 
    <li>Milk</li>
    <script type="text/javascript">
    alert(document.getElementsByTagName("li").length);
    </script>
  </ul>
</body>
Run Code Online (Sandbox Code Playgroud)

当我试图将脚本放入正文时,结果显示2.为什么存在这样的差异?主要区别是什么?

html javascript

38
推荐指数
5
解决办法
4万
查看次数

unity3D:使用socket.io连接到node.js

我试图使用socket.io将我的unity3d程序与node.js服务器连接起来.有可能吗?如果可能的话,请分享这个文件或步骤....

大多数人使用"unity socket.io"将unity3d程序与node.js服务器连接起来.我在SO 连接Unity3d和Node.js中找到了一个问题,用于unity socket.io.但我需要socket.io.如何安装此模块.请分享这个........

unity-game-engine node.js socket.io

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

html ×1

javascript ×1

node.js ×1

socket.io ×1

unity-game-engine ×1