• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
龙星之峰
抓住时间,改变现状
博客园    首页    新随笔    联系   管理    订阅  订阅

Javascript学习与实践(3)

 Js用在那里?

        Js用在<head>和<body>中是有区别的,JS在BODY块中,页面一加载就会去解析执行它,JS在HEAD中需要调用才能执行,所以一般建议在要调用的HEAD中

         例子:文档中在HEAD页面包含的功能脚本,我们能确保他,早调用之前就被加载到页面中

 

<html>
<head>
<script type="text/javascript">
function message()
{
alert("This alert box was called with the onload event")
}
</script>
</head>

<body onload="message()">

</body>
</html>

         body块中,执行放在里面的脚本,

 

<html>
<head>
</head>

<body>

<script type="text/javascript">
document.write("This message is written when the page loads")
</script>

</body>
</html>

         外部的脚本----怎么链接一个外部文件脚本

 

<html>
<head>
</head>
<body>

<script src="xxx.js">
</script>

<p>
The actual script is in an external script file called "xxx.js".
</p>

</body>
</html>

posted @ 2007-01-20 15:58  lxsohu  阅读(311)  评论(3)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3