JS基础

来源:互联网 发布:ubuntu双系统启动顺序 编辑:程序博客网 时间:2024/06/06 09:58

JS中类和对象实例
index.js文件(采用外联)

//创建构造函数function Person(){}//创建对象var person = new Person;person.name = "美女"; person.age = 24;person.height = 168;person.weigth = 45;person.hello = function(){    alert("你好")}person.hello();alert(person);

index.html文件:

<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Insert title here</title><script type="text/javascript" src="index.js"></script></head><body></body></html>

js的三种使用方式:

<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Insert title here</title><!-- 3.外部引用 --><script type="text/javascript" src="test.js"></script></head><body>    <!--          使用JavaScript的方式: 1. 在a标签内部使用                           2.html页面引用                           3.外部引用(外链)    --><!--        <script type="text/javascript">        var msg = "全局变量";        function show(){            msg = "局部变量";        }        show();        alert(msg);    </script>-->     <script  type="text/javascript">        var msg = "全局变量";        function show()        {            var msg;             msg = "局部变量";        }        show();        alert(msg);    </script></body></html>
原创粉丝点击