1 <!DOCTYPE html>
2 <html 3 head 4 meta charset="UTF-8" 5 title></ 6 script 7 var person = {
8 name: "jiangzhou, 9 age: 2210 showName: function(){
11 alert(this); //[Object Object]
12 姓名:+.name);
13 },1)">14 showAge: 15 年龄:.age);
16 }
17 };
18 person.showName();
19 person.showAge();
20
21 </22 23 >
仿java.lang包
8 lang {};
9
10 /**
* 仿java.lang.Math类
12 */
lang.Math 14 * 求绝对值
* @param {Object} a
17 abs: (a){
19 return a > 0 ? a : -a;
20 21 22 * 求最大值
23 24 * @param {Object} b
25 26 max: (a,b){
27 > b a : b;
28 29 30 * PI
31 32 PI: 3.1415926
33 }
34
35 36 * 仿java.lang.String类
37 38 lang.String 39 40 * 求字符串长度
41 * @param {Object} str
42 43 length: (str){
44 str.length;
45 46 47 * 将字符串转为小写
48 49 50 toLowerCase: 51 str.toLowerCase();
52 53 54 * 将字符串转为大写
55 56 57 toUpperCase: 58 str.toUpperCase();
59 60 61
62 调用
63 alert(lang.Math.abs(19)); 19
64 alert(lang.Math.PI);
65 alert(lang.String.toUpperCase(abcdefgABCDEFG
66
67 68 69 >
="UTF-8" />
4 6
* Person 父类 人
* @param {Object} name 姓名
* @param {Object} sex 性别
11 12 Person(name,sex){
13 .name name;
.sex sex;
Person.prototype.showName = alert(.name);
Person.prototype.showSex 性别:.sex);
21 22
23 -----------------------------------------------------24
25 * Student 学生 继承 人
27 * @param {Object} name
* @param {Object} sex
29 * @param {Object} major 学生特有属性:专业
30 31 Student(name,sex,major){
32 调用父类的构造函数
Person.call(34
35 添加自己的属性
36 .major major;
37 38 继承父类原型中的方法
39 Student.prototype Person.prototype;
40 添加自己特有的方法
Student.prototype.showMajor 42 专业:.major);
44
45 student new Student(bojiangzhou男信息管理);
46 student.showName();
student.showSex();
student.showMajor();
49
alert(Person.prototype.showMajor);
51 52 53 >
5 6 7 arr1 [12345];
8 arr2 arr1;
9
arr2.push(611
alert(arr1); 弹出1,2,3,4,5,6
alert(arr2); 14
alert(typeof arr1); object
arr2); 17 18 >
[];
10 复制arr1的数据即可
11 for( i0;i<arr1.length;i++){
arr2[i]arr1[i];
}
16
19
20 21 >
39 p in Person.prototype){
Student.prototype[p] Person.prototype[p];
42
43 44 47
48 49 51 52
53 54 55 56 >
/* * 拖拽
3 * @param {Object} id div的id
4 5 function Drag(id){
this.oBox = document.getElementById(id);
7 this.disX = 0;
8 this.disY = 0 9
10 var _this = this11
12 this.oBox.onmousedown = 13 _this.fnDown();
14 }
15 }
16 //鼠标按下
17 Drag.prototype.fnDown = (ev){
18 var oEvent = ev || event;
19
this.disX = oEvent.clientX - .oBox.offsetLeft;
21 this.disY = oEvent.clientY - .oBox.offsetTop;
22
23 24
25 document.onmousemove = 26 _this.fnMove();
27 };
28 document.onmouseup = 29 _this.fnUp();
30 31 32 鼠标移动
33 Drag.prototype.fnMove = 34 var oEvent= ev ||35
36 this.oBox.style.left = oEvent.clientX - this.disX + 'px'37 this.oBox.style.top = oEvent.clientY - this.disY + 'px'38 39 鼠标抬起
40 Drag.prototype.fnUp = 41 document.onmousemove = null42 document.onmouseup = 43 }
style 6 div {
7 position: absolute;
}
9 10 >拖拽11 script type="text/javascript" src="../js/drag.js" 12 window.onload drag1 Drag(box115
16 box218 19 20
bodydiv id="box1" style="background: red;width: 200px;height: 200px;"div23
24 ="box2"="background: blue;width: 100px;height: 300px;"25 >
* 限制边界的拖拽,继承自Drag
* @param {Object} id
DragLimit(id){
6 Drag.call( 7 8 继承方法
9 for(var p in Drag.prototype){
10 DragLimit.prototype[p] = Drag.prototype[p];
11 12 * 覆写父类的鼠标移动方法,控制不能移出边界
14 15 DragLimit.prototype.fnMove = 16 17
var left = oEvent.clientX - .disX;
var top = oEvent.clientY - .disY;
20
控制边界
if(left < 023 left = 024 } else if(left > document.documentElement.clientWidth-.oBox.offsetWidth){
25 left = document.documentElement.clientWidth-.oBox.offsetWidth;
27 if(top <= 028 top = 029 } if(top > document.documentElement.clientHeight-.oBox.offsetHeight){
30 top = document.documentElement.clientHeight-.oBox.offsetHeight;
32
33 this.oBox.style.left = left + 'px'this.oBox.style.top = top + 'px'35 }
body padding 0 margin 9 13 14 15 16 ="../js/dragLimit.js" 17 19 20
DragLimit(23 25
28
29 >