日期:2014-05-16  浏览次数:20352 次

js初次加载页面的时候执行函数的方法
(1)
<html>
<head>
<title>
</title>
</head>
<body>
<p>
p1
</p>
<p>
p2
</p>
</body>
</html>
<script type="text/javascript">
  aa();
  function aa (){
  alert("nihao");
  alert(document.getElementsByTagName("p"));
  }
</script>

(2)
<html>
<head>
<title>
</title>
<script type="text/javascript">
  function aa (){
  alert("nihao");
  alert(document.getElementsByTagName("p"));
  }
</script>
</head>
<body>
<p>
p1
</p>
<p>
p2
</p>
</body>
</html>
<script type="text/javascript">
  aa();
</script>

(3)
<html>
<head>
<title>
</title>
<script type="text/javascript">
  aa();
  function aa (){
  alert("nihao");
  alert(document.getElementsByTagName("p"));
  }
</script>
</head>
<body>
<p>
p1
</p>
<p>
p2
</p>
</body>
</html>