prototype
一个类型如何从另一个类型继承
实例代码:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46function Class1() {
this.field1 = 1;
this.method1 = function() {
alert(1);
}
}
function Class2() {
this.field2 = 2;
this.method2 = function() {
alert(2);
}
}
Class2.prototype = new Class1(); //关键代码
//测试
var myObject1 = new Class1();
alert(myObject1.field1); //1
if (myObject1.method1) { //true
myObject1.method1();
} else {
alert("myObject1.mehtod1 is undefined");
}
alert(myObject1.field2); //undefined
if (myObject1.method2) {
myObject1.method2();
} else {
alert("myObject1.mehtod2 is undefined");
}
var myObject2 = new Class2();
alert(myObject2.field1); //2
if (myObject2.method1) { //true
myObject2.method1();
} else {
alert("myObject2.mehtod1 is undefined");
}
alert(myObject2.field2); //2
if (myObject2.method2) { //true
myObject2.method2();
} else {
alert("myObject2.mehtod2 is undefined");
}
附:1
2
3
4
5
6
7var windowHeight = $(window).height(); //浏览器时下窗口可视区域高度;
var scrollTop = $(document).scrollTop(); //获取滚动条到顶部的垂直高度;
var documentHeight = $(document.body).height(); //浏览器时下窗口文档body的高度;
var windowHeight = $(window).height(); //浏览器时下窗口可视区域高度;
var scrollTop = $(document).scrollTop(); //获取滚动条到顶部的垂直高度;
var documentHeight = $(document.body).height(); //浏览器时下窗口文档body的高度;
URL传递中文之JavaScript encodeURIComponent
使用URL传递中文等特殊符号时,可以使用encodeURIComponent进行encode一下,服务器端接收后,进行dencode,可以避免乱码
通过原生JS获取iframe内容物 示例:
1 | console.info(document.getElementById('iframeId').context.contentWindow.document); |
将滚动条内的指定元素显示在可视区域
1 | var index = parseInt(value) - 1; // 指定元素的索引 |