HTML下js使用方式

xiaoxiao2021-02-28  13

    大体上可分为三种,一,在HTML内部直接,在定义事件时,写入javascript脚本代码。二,嵌入<scrpit>标签。三、调用js文件。

    第一种:

   <input type="button" value="按钮" οnclick="alter('hello world')">

    第二种标签:

    <script>可以用在<head>和<body>中。

   1 . 标签第一种方式

    <head>

         <script type="text/javascript" language="javascript">

                alert("Hello world");

         </script>

    </head>

    2 . 标签第二种方式 

    <head>

         <script type="text/javascript" language="javascript">

                function method1() {

                alert("Hello world");

                }

         </script>

    </head>

    第三种调用js方式:

    对于较大量的JavaScript代码,单独写入js文件中,调用。

    js文件:

        function method ( ) {

         alert("hello world!");

}

    HTML页面

     <head>

           <script language="javascript" src="js文件路径及名称"  type="text/javascript">

           </script>

     </head>

转载请注明原文地址: https://www.6miu.com/read-250423.html

最新回复(0)