JS入门

来源:互联网 发布:大同集宁之战 知乎 编辑:程序博客网 时间:2024/05/16 00:47
先来说说如何在网页上显示内容
<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>在网页上显示helloworld</title>    <script type="text/javascript">        document.write("helloworld")    </script></head><body></body></html>
                         行内js
<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>js使用方式一,行内js</title></head><body>         <input type="button" value="点击有惊喜" onclick="javascript:alert('嘻嘻嘻')"/><input type="button" value="点我试试啊" onclick="javascript:alert('surprise')"/><input type="button" value="双击" ondblclick="javascript:alert('surprise')"/></body></html>
                         内部js
     
<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>js使用方式二,内部js</title>    <script type="text/javascript">        //定义函数        function surprise(){            alert('恭喜你')        }    </script></head><body><input type="button" value="点击有惊喜" onclick="surprise()"/></body></html>
                          外部js
<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>js使用方式三,外部js</title>    <script src="../../js/test.js" type=""></script>    ← 通过路径寻找    
   使 用外部js文件,通过script标签导入, src属性是指定js文件路径的      标签必须分成两部分         标签内 不允许添加任何代码
</head><body><input type="button" value="点击" onclick="test()"/></body></html>

 
原创粉丝点击