`
yunmoxue
  • 浏览: 285433 次
  • 性别: Icon_minigender_1
  • 来自: 郑州
社区版块
存档分类
最新评论

嵌入javascript三种方法

    博客分类:
  • ajax
阅读更多
1.直接调用
    使用<script>和</script>标记在需要的位置编写javascript程序.
例:
   <p>
   <script language="javascript">
   alert("Hi~~");
   </script>
   </p>
2.事件调用
    通过在html 标记的事件中使用javascript 程序,例如单击事件,鼠标移动和载入事件等
例 1:
 
 <head>
   <script language="javascript">
   function hello(){
   alert("Hi~~");
   }
   </script>
   </head>
   <body>
   <p onclick="hello()">
   hello~~
   </p>
   </body>
例 2:
  
<head>
   <script language="javascript">
   function hello(){
   alert("Hi~~");
   }
   </script>
   </head>
   <body>
   <script>
   hello();
   </script>
   </body>
3.外部连接调用
    在单独的.js 文件中编写 javascript 程序,然后在html文件中连接到.js的文件,并在相应的位置调用
例:
   文件:hello.js
  
function hello(){
   alert("Hi~~");
   }
   文件:hello.html
   <head>
   <!--js文件必须与heml在同一文件夹,才能写相对路径-->
   <script language="javascript" src="hello.js"></script>
   </head>
   <body>
   <p onclick="hello()">
   hello~~~
   </p>
   </body>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics