-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDOM.html
245 lines (220 loc) · 5.1 KB
/
DOM.html
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
.wrap{
background: #d7eff8;
}
.wrap1{
height: 2000px;
width: 1000px;
margin: 0 auto;
padding-top: 20px;
background: #e6ccf2;
}
.wrap2{
height: 300px;
background: #f5eeee;
margin: 20px auto 20px ;
}
.wrap3{
height: 300px;
background: #f5eeee;
margin: 0px auto 20px ;
}
.wrap4{
height: 50px;
width: 50px;
line-height: 50px;
text-align: center;
background: #d1f3cc;
position: fixed;/*定位到 右下角*/
right: 0;
bottom: 0;
}
</style>
</head>
<body>
<div class="wrap" >
<input id="btn" type="button" value="打开窗口">
<input id="btn1" type="button" value="打印窗口">
<input id="btn2" type="button" value="confirm()方法">
<input id="btn3" type="button" value="prompt()方法">
<input id="btn4" type="button" value="scrollTo()方法">
<input id="btn5" type="button" value="scrollTo()方法的例子">
<input id="btn6" type="button" value="navigator的属性">
<input id="btn7" type="button" value="userAgent返回浏览器头部信息">
</div>
<div class="wrap1">
<div class="wrap3">1</div>
<div class="wrap2">2</div>
<div class="wrap2">3</div>
<div class="wrap2">4</div>
<div class="wrap2">5</div>
<div class="wrap2">6</div>
<div class="wrap2">7</div>
<div id="div1" class="wrap4">GOTop</div>
</div>
</body>
<script>
console.log("文档显示区Height"+window.innerHeight);
console.log("文档显示区Widht"+window.innerWidth);
console.log("外部Height"+window.outerHeight);
console.log("外部Height"+window.outerWidth);
var btn = document.getElementById("btn");
var btn1 = document.getElementById("btn1");
var btn2 = document.getElementById("btn2");
var btn3 = document.getElementById("btn3");
var btn4 = document.getElementById("btn4");
var div1 = document.getElementById("div1");
var btn6 = document.getElementById("btn6");
var btn7 = document.getElementById("btn7");
/******************************************/
btn.onclick = function()
{
window.open("http://www.sina.com.cn","1");
}
/******************************************/
btn1.onclick = function ()
{
window.print();
}
/******************************************/
btn2.onclick = function ()
{
var k = window.confirm("confirm()的方法返回true或false");
if(k)
{
document.write("返回了true");
}
else
{
document.write("返回了false");
}
}
/******************************************/
btn3.onclick = function()
{
var num1 = Math.ceil(Math.random()*100);
alert("产生的随机数"+num1);
var j=0;
var mak1 = false;
for(var i=0; i<10; i++)
{
j++;
var name = prompt("请输入1--100以内的数字");
name = Number(name);
if(name == null )
{
break;
}
if( !name )
{
alert("输入有误");
// continue;
}
if( name > num1)
{
alert("大了");
}
else if(name < num1)
{
alert("小了");
}
else if(name === num1)
{
alert("猜对了");
break;
}
if(j==10)
{
alert("智商欠费");
var k = confirm("是否需要充值?")
if(k)
{
i-=3;
j-=3;
}
}
}
//注意 Prompt 获取到的是字符串
}
/******************************************/
btn4.onclick = function()
{
scrollTo(0,1200);//跳转到 指定坐标
alert("跳转到 0,1200px");
// console.log(document.body.scrollTo);
}
/******************************************/
div1.onclick = function ()
{
var inter =setInterval(function(){
// console.log(document.body.scrollTop);
//获取当前的滚动值
var st = document.body.scrollTop || document.documentElement.scrollTop;
st/=2;
scrollTo(0,st);
if(st<=1)
{
clearInterval(inter);
}
},30);
}
btn6.onclick = function()
{
console.log("浏览器的代码名"+navigator.appCodeName);
console.log("浏览器的名称"+navigator.appName);
console.log("浏览器的平台和版本信息"+navigator.appVersion);
console.log("浏览器是否启用cookie"+navigator.cookieEnabled);
console.log("运行浏览器的操作系统平台"+navigator.platform);
console.log("由客户机发送服务器的 user-agent 头部信息"+navigator.userAgent);
}
btn7.onclick = function()
{
var userAgent = navigator.userAgent;
console.log(userAgent);
if(userAgent.indexOf("Chrome") != -1)
{
console.log("您在使用的是Chrome浏览器");
}
else if(userAgent.indexOf("Firefox") != -1)
{
console.log("您在使用的是Firefox浏览器");
}
else if(userAgent.indexOf("MSIE") != -1)
{
console.log("您在使用的是IE浏览器");
}
}
function myBrowser(){
var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
if (userAgent.indexOf("Opera") > -1;)
{
alert("你在使用的 IE");
};
if (userAgent.indexOf("Firefox") > -1)
{
alert("你在使用的 Firefox");
}
if (userAgent.indexOf("Chrome") > -1)
{
alert("你在使用的 Chrome");
}
if (userAgent.indexOf("Safari") > -1)
{
alert("你在使用的 Opera");
}
if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera)
{
alert("你在使用的 Safari");
};
}
</script>
</html>