zoukankan
html css js c++ java
Javascript 常用方法示例
1事件源对象
2event.srcElement.tagName
3event.srcElement.type
4捕获释放
5event.srcElement.setCapture();
6event.srcElement.releaseCapture();
7事件按键
8event.keyCode
9event.shiftKey
10event.altKey
11event.ctrlKey
12事件返回值
13event.returnValue
14鼠标位置
15event.x
16event.y
17窗体活动元素
18document.activeElement
19绑定事件
20document.captureEvents(Event.KEYDOWN);
21访问窗体元素
22document.all(
"
txt
"
).focus();
23document.all(
"
txt
"
).select();
24窗体命令
25document.execCommand
26窗体COOKIE
27document.cookie
28菜单事件
29document.oncontextmenu
30创建元素
31document.createElement(
"
SPAN
"
);
32根据鼠标获得元素:
33document.elementFromPoint(event.x,event.y).tagName
==
"
TD
34document.elementFromPoint(event.x,event.y).appendChild(ms)
35窗体图片
36document.images[索引]
37窗体事件绑定
38document.onmousedown=scrollwindow;
39元素
40document.窗体.elements[索引]
41对象绑定事件
42document.all.xxx.detachEvent('onclick',a);
43插件数目
44navigator.plugins
45取变量类型
46typeof($js_libpath) ==
"
undefined
"
47下拉框
48下拉框.options[索引]
49下拉框.options.length
50查找对象
51document.getElementsByName(
"
r1
"
);
52document.getElementById(id);
53定时
54timer=setInterval('scrollwindow()',delay);
55clearInterval(timer);
56UNCODE编码
57escape() ,unescape
58父对象
59obj.parentElement(dhtml)
60obj.parentNode(dom)
61交换表的行
62TableID.moveRow(2,1)
63替换CSS
64document.all.csss.href =
"
a.css
"
;
65并排显示
66display:inline
67隐藏焦点
68hidefocus=true
69根据宽度换行
70style=
"
word
-
break
:
break
-
all
"
71自动刷新
72<meta HTTP-EQUIV=
"
refresh
"
CONTENT=
"
8
;URL
=
http:
//
c98.yeah.net">
73简单邮件
74
<
a href
=
"
mailto:aaa@bbb.com?subject=ccc&body=xxxyyy
"
>
75快速转到位置
76obj.scrollIntoView(
true
)
77锚
78
<
a name
=
"
first
"
>
79
<
a href
=
"
#first
"
>
anchors
</
a
>
80网页传递参数
81location.search();
82可编辑
83obj.contenteditable
=
true
84执行菜单命令
85obj.execCommand
86双字节字符
87
/
[
^
\x00
-
\xff]
/
88汉字
89
/
[\u4e00
-
\u9fa5]
/
90让英文字符串超出表格宽度自动换行
91word
-
wrap:
break
-
word; word
-
break
:
break
-
all;
92透明背景
93
<
IFRAME src
=
"
1.htm
"
width
=
300
height
=
180
allowtransparency
></
iframe
>
94获得style内容
95obj.style.cssText
96HTML标签
97document.documentElement.innerHTML
98第一个style标签
99document.styleSheets[
0
]
100style标签里的第一个样式
101document.styleSheets[
0
].rules[
0
]
102防止点击空链接时,页面往往重置到页首端。
103
<
a href
=
"
javascript:function()
"
>
word
</
a
>
104上一网页源
105asp:
106request.servervariables(
"
HTTP_REFERER
"
)
107javascript:
108document.referrer
109释放内存
110CollectGarbage();
111禁止右键
112document.oncontextmenu
=
function
()
{
return
false
;}
113禁止保存
114
<
noscript
><
iframe src
=
"
*.htm
"
></
iframe
></
noscript
>
115禁止选取
<
body oncontextmenu
=
"
return false
"
ondragstart
=
"
return false
"
onselectstart
=
"
return false
"
onselect
=
"
document.selection.empty()
"
oncopy
=
"
document.selection.empty()
"
onbeforecopy
=
"
return false
"
onmouseup
=
"
document.selection.empty()>
116禁止粘贴
117<input type=text onpaste=
"
return
false
"
>
118地址栏图标
119<link rel=
"
Shortcut Icon
"
href=
"
favicon.ico
"
>
120favicon.ico 名字最好不变16*16的16色,放虚拟目录根目录下
121收藏栏图标
122<link rel=
"
Bookmark
"
href=
"
favicon.ico
"
>
123查看源码
124<input type=button value=查看网页源代码 onclick=
"
window.location
=
'view
-
source:'
+
'http:
//
www.csdn.net/'">
125关闭输入法
126
<
input style
=
"
ime-mode:disabled
"
>
127自动全选
128
<
input type
=
text name
=
text1 value
=
"
123
"
onfocus
=
"
this.select()
"
>
129ENTER键可以让光标移到下一个输入框
130
<
input onkeydown
=
"
if(event.keyCode==13)event.keyCode=9
"
>
131文本框的默认值
132
<
input type
=
text value
=
"
123
"
onfocus
=
"
alert(this.defaultValue)
"
>
133title换行
134obj.title
=
"
123 sdfs
"
135获得时间所代表的微秒
136
var
n1
=
new
Date(
"
2004-10-10
"
.replace(
/-/
g,
"
\/
"
)).getTime()
137窗口是否关闭
138win.closed
139checkbox扁平
140
<
input type
=
checkbox style
=
"
position: absolute; clip:rect(5px 15px 15px 5px)
"
><
br
>
141获取选中内容
142document.selection.createRange().duplicate().text
143自动完成功能
144
<
input type
=
text autocomplete
=
on
>
打开该功能
145
<
input type
=
text autocomplete
=
off
>
关闭该功能
146窗口最大化
147
<
body onload
=
"
window.resizeTo(window.screen.width - 4,window.screen.height-50);window.moveTo(-4,-4)
"
>
148无关闭按钮IE
149window.open(
"
aa.htm
"
,
"
meizz
"
,
"
fullscreen=7
"
);
150统一编码
/
解码
151alert(decodeURIComponent(encodeURIComponent(
"
http://你好.com?as= hehe
"
)))
152encodeURIComponent对
"
:
"
、
"
/
"
、
"
;
"
和
"
?
"
也编码
153表格行指示
154
<
tr onmouseover
=
"
this.bgColor='#f0f0f0'
"
onmouseout
=
"
this.bgColor='#ffffff'
"
>
155
156
//
各种尺寸
157
158s
+=
"
\r\n网页可见区域宽:
"
+
document.body.clientWidth;
159s
+=
"
\r\n网页可见区域高:
"
+
document.body.clientHeight;
160s
+=
"
\r\n网页可见区域高:
"
+
document.body.offsetWeight
+
"
(包括边线的宽)
"
;
161s
+=
"
\r\n网页可见区域高:
"
+
document.body.offsetHeight
+
"
(包括边线的宽)
"
;
162s
+=
"
\r\n网页正文全文宽:
"
+
document.body.scrollWidth;
163s
+=
"
\r\n网页正文全文高:
"
+
document.body.scrollHeight;
164s
+=
"
\r\n网页被卷去的高:
"
+
document.body.scrollTop;
165s
+=
"
\r\n网页被卷去的左:
"
+
document.body.scrollLeft;
166s
+=
"
\r\n网页正文部分上:
"
+
window.screenTop;
167s
+=
"
\r\n网页正文部分左:
"
+
window.screenLeft;
168s
+=
"
\r\n屏幕分辨率的高:
"
+
window.screen.height;
169s
+=
"
\r\n屏幕分辨率的宽:
"
+
window.screen.width;
170s
+=
"
\r\n屏幕可用工作区高度:
"
+
window.screen.availHeight;
171s
+=
"
\r\n屏幕可用工作区宽度:
"
+
window.screen.availWidth;
172
//
过滤数字
173
174
<
input type
=
text onkeypress
=
"
return event.keyCode>=48&&event.keyCode<=57||(this.value.indexOf('.')<0?event.keyCode==46:false)
"
onpaste
=
"
return !clipboardData.getData('text').match(/\D/)
"
ondragenter
=
"
return false
"
>
175
176
177
178
//
特殊用途
179
180
<
input type
=
button value
=
导入收藏夹 onclick
=
"
window.external.ImportExportFavorites(true,'http://localhost');
"
>
181
<
input type
=
button value
=
导出收藏夹 onclick
=
"
window.external.ImportExportFavorites(false,'http://localhost');
"
>
182
<
input type
=
button value
=
整理收藏夹 onclick
=
"
window.external.ShowBrowserUI('OrganizeFavorites', null)
"
>
183
<
input type
=
button value
=
语言设置 onclick
=
"
window.external.ShowBrowserUI('LanguageDialog', null)
"
>
184
<
input type
=
button value
=
加入收藏夹 onclick
=
"
window.external.AddFavorite('http://www.google.com/', 'google')
"
>
185
<
input type
=
button value
=
加入到频道 onclick
=
"
window.external.addChannel('http://www.google.com/')
"
>
186
<
input type
=
button value
=
加入到频道 onclick
=
"
window.external.showBrowserUI('PrivacySettings',null)
"
>
187
188
189
190
//
不缓存
191
<
META HTTP
-
EQUIV
=
"
pragma
"
CONTENT
=
"
no-cache
"
>
192
<
META HTTP
-
EQUIV
=
"
Cache-Control
"
CONTENT
=
"
no-cache, must-revalidate
"
>
193
<
META HTTP
-
EQUIV
=
"
expires
"
CONTENT
=
"
0
"
>
194
195
196
197
198
199
200
//
正则匹配
201
202
203匹配中文字符的正则表达式: [\u4e00
-
\u9fa5]
204匹配双字节字符(包括汉字在内):[
^
\x00
-
\xff]
205匹配空行的正则表达式:\n[\s
|
]
*
\r
206匹配HTML标记的正则表达式:
/<
(.
*
)
>
.
*<
\
/
\
1
>|<
(.
*
) \
/>/
207匹配首尾空格的正则表达式:(
^
\s
*
)
|
(\s
*
$)(像vbscript那样的trim函数)
208匹配Email地址的正则表达式:\w
+
([
-+
.]\w
+
)
*
@\w
+
([
-
.]\w
+
)
*
\.\w
+
([
-
.]\w
+
)
*
209匹配网址URL的正则表达式:http:
//
([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
210以下是例子:
211利用正则表达式限制网页表单里的文本框输入内容:
212用正则表达式限制只能输入中文:onkeyup
=
"
value=value.replace(/[^\u4E00-\u9FA5]/g,'')
"
onbeforepaste
=
"
clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))
"
2131
.用正则表达式限制只能输入全角字符: onkeyup
=
"
value=value.replace(/[^\uFF00-\uFFFF]/g,'')
"
onbeforepaste
=
"
clipboardData.setData('text',clipboardData.getData('text').replace(/[^\uFF00-\uFFFF]/g,''))
"
2142
.用正则表达式限制只能输入数字:onkeyup
=
"
value=value.replace(/[^\d]/g,'')
"
onbeforepaste
=
"
clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))
"
2153
.用正则表达式限制只能输入数字和英文:onkeyup
=
"
value=value.replace(/[\W]/g,'')
"
onbeforepaste
=
"
clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))
"
216
//
消除图像工具栏
217
218
<
IMG SRC
=
"
mypicture.jpg
"
HEIGHT
=
"
100px
"
WIDTH
=
"
100px
"
GALLERYIMG
=
"
false
"
>
219or
220
<
head
>
221
<
meta http
-
equiv
=
"
imagetoolbar
"
content
=
"
no
"
>
222
</
head
>
223
224
225
226
//
无提示关闭
227
228
229
function
Close()
230
{
231
var
ua
=
navigator.userAgent
232
var
ie
=
navigator.appName
==
"
Microsoft Internet Explorer
"
?
true
:
false
233
if
(ie)
234
{
235
var
IEversion
=
parseFloat(ua.substring(ua.indexOf(
"
MSIE
"
)
+
5
,ua.indexOf(
"
;
"
,ua.indexOf(
"
MSIE
"
))))
236
if
(IEversion
<
5.5
)
237
{
238
var
str
=
'
<
object id
=
noTipClose classid
=
"
clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11
"
>
'
239
str
+=
'
<
param name
=
"
Command
"
value
=
"
Close
"
></
object
>
';
240
document.body.insertAdjacentHTML(
"
beforeEnd
"
, str);
241
document.all.noTipClose.Click();
242
}
243
else
244
{
245
window.opener
=
null
;
246
window.close();
247
}
248
}
249
else
250
{
251
window.close()
252
}
253
}
254
//
取得控件得绝对位置(1)
255
256
257
<
script language
=
"
javascript
"
>
258
function
getoffset(e)
259
{
260
var
t
=
e.offsetTop;
261
var
l
=
e.offsetLeft;
262
while
(e
=
e.offsetParent)
263
{
264
t
+=
e.offsetTop;
265
l
+=
e.offsetLeft;
266
}
267
var
rec
=
new
Array(
1
);
268
rec[
0
]
=
t;
269
rec[
1
]
=
l;
270
return
rec
271
}
272
</
script
>
273
//
获得控件的绝对位置(2)
274
275oRect
=
obj.getBoundingClientRect();
276oRect.left
277oRect.
278
//
最小化,最大化,关闭
279
280
<
object id
=
min classid
=
"
clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11
"
>
281
<
param name
=
"
Command
"
value
=
"
Minimize
"
></
object
>
282
<
object id
=
max classid
=
"
clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11
"
>
283
<
param name
=
"
Command
"
value
=
"
Maximize
"
></
object
>
284
<
OBJECT id
=
close classid
=
"
clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11
"
>
285
<
PARAM NAME
=
"
Command
"
value
=
"
Close
"
></
OBJECT
>
286
<
input type
=
button value
=
最小化 onclick
=
min.Click()
>
287
<
input type
=
button value
=
最大化 onclick
=
max.Click()
>
288
<
input type
=
button value
=
关闭 onclick
=
close.Click()
>
289
290
291
292
293
294
295
//
光标停在文字最后
296
297
298
299
<
script language
=
"
javascript
"
>
300
function
cc()
301
{
302
var
e
=
event.srcElement;
303
var
r
=
e.createTextRange();
304
r.moveStart('character',e.value.length);
305
r.collapse(
true
);
306
r.select();
307
}
308
</
script
>
309
<
input type
=
text name
=
text1 value
=
"
123
"
onfocus
=
"
cc()
"
>
310
//
页面进入和退出的特效
311
312
313进入页面
<
meta http
-
equiv
=
"
Page-Enter
"
content
=
"
revealTrans(duration=x, transition=y)
"
>
314推出页面
<
meta http
-
equiv
=
"
Page-Exit
"
content
=
"
revealTrans(duration=x, transition=y)
"
>
315这个是页面被载入和调出时的一些特效。duration表示特效的持续时间,以秒为单位。transition表示使
316用哪种特效,取值为1
-
23
:
317
0
矩形缩小
318
1
矩形扩大
319
2
圆形缩小
320
3
圆形扩大
321
4
下到上刷新
322
5
上到下刷新
323
6
左到右刷新
324
7
右到左刷新
325
8
竖百叶窗
326
9
横百叶窗
327
10
错位横百叶窗
328
11
错位竖百叶窗
329
12
点扩散
330
13
左右到中间刷新
331
14
中间到左右刷新
332
15
中间到上下
333
16
上下到中间
334
17
右下到左上
335
18
右上到左下
336
19
左上到右下
337
20
左下到右上
338
21
横条
339
22
竖条
340
23
341
//
网页是否被检索
342
343
<
meta name
=
"
ROBOTS
"
content
=
"
属性值
"
>
344
其中属性值有以下一些:
345
属性值为
"
all
"
: 文件将被检索,且页上链接可被查询;
346
属性值为
"
none
"
: 文件不被检索,而且不查询页上的链接;
347
属性值为
"
index
"
: 文件将被检索;
348
属性值为
"
follow
"
: 查询页上的链接;
349
属性值为
"
noindex
"
: 文件不检索,但可被查询链接;
350
属性值为
"
nofollow
"
:
351
352
353
354
355
//
打印分页
356
357
<
p style
=
"
page-break-after:always
"
>
page1
</
p
>
358
<
p style
=
"
page-break-after:always
"
>
page2
</
p
>
359
360
361
362
363
//
设置打印
364
365
366
<
object id
=
"
factory
"
style
=
"
display:none
"
viewastext
367
classid
=
"
clsid:1663ed61-23eb-11d2-b92f-008048fdd814
"
368
codebase
=
"
http://www.meadroid.com/scriptx/ScriptX.cab#Version=5,60,0,360
"
369
></
object
>
370
<
input type
=
button value
=
页面设置 onclick
=
"
factory.printing.PageSetup()
"
>
371
<
input type
=
button value
=
打印预览 onclick
=
"
factory.printing.Preview()
"
>
372
373
<
script language
=
javascript
>
374
function
window.onload()
375
{
376
//
-- advanced features
377
factory.printing.SetMarginMeasure(
2
)
//
measure margins in inches
378
factory.printing.SetPageRange(
false
,
1
,
3
)
//
need pages from 1 to 3
379
factory.printing.printer
=
"
HP DeskJet 870C
"
380
factory.printing.copies
=
2
381
factory.printing.collate
=
true
382
factory.printing.paperSize
=
"
A4
"
383
factory.printing.paperSource
=
"
Manual feed
"
384
//
-- basic features
385
factory.printing.header
=
"
居左显示&b居中显示&b居右显示页码,第&p页/共&P页
"
386
factory.printing.footer
=
"
(自定义页脚)
"
387
factory.printing.portrait
=
false
388
factory.printing.leftMargin
=
0.75
389
factory.printing.topMargin
=
1.5
390
factory.printing.rightMargin
=
0.75
391
factory.printing.bottomMargin
=
1.5
392
}
393
function
Print(frame)
{
394
factory.printing.Print(
true
, frame)
//
print with prompt
395
}
396
</
script
>
397
<
input type
=
button value
=
"
打印本页
"
onclick
=
"
factory.printing.Print(false)
"
>
398
<
input type
=
button value
=
"
页面设置
"
onclick
=
"
factory.printing.PageSetup()
"
>
399
<
input type
=
button value
=
"
打印预览
"
onclick
=
"
factory.printing.Preview()
"
><
br
>
400
<
a href
=
"
http://www.meadroid.com/scriptx/docs/printdoc.htm?static
"
target
=
_blank
>
具体使用手册,更多信息,点这里
</
a
>
401
402
//
自带的打印预览
403
404WebBrowser.ExecWB(
1
,
1
) 打开
405Web.ExecWB(
2
,
1
) 关闭现在所有的IE窗口,并打开一个新窗口
406Web.ExecWB(
4
,
1
) 保存网页
407Web.ExecWB(
6
,
1
) 打印
408Web.ExecWB(
7
,
1
) 打印预览
409Web.ExecWB(
8
,
1
) 打印页面设置
410Web.ExecWB(
10
,
1
) 查看页面属性
411Web.ExecWB(
15
,
1
) 好像是撤销,有待确认
412Web.ExecWB(
17
,
1
) 全选
413Web.ExecWB(
22
,
1
) 刷新
414Web.ExecWB(
45
,
1
) 关闭窗体无提示
415
<
style media
=
print
>
416
.Noprint
{display:none;}
<!--
用本样式在打印时隐藏非打印项目
-->
417
.PageNext
{page
-
break
-
after: always;}
<!--
控制分页
-->
418
</
style
>
419
<
object id
=
"
WebBrowser
"
width
=
0
height
=
0
classid
=
"
CLSID:8856F961-340A-11D0-A96B-00C04FD705A2
"
>
420
</
object
>
421
422
<
center class
=
"
Noprint
"
>
423
<
input type
=
button value
=
打印 onclick
=
document.all.WebBrowser.ExecWB(
6
,
1
)
>
424
<
input type
=
button value
=
直接打印 onclick
=
document.all.WebBrowser.ExecWB(
6
,
6
)
>
425
<
input type
=
button value
=
页面设置 onclick
=
document.all.WebBrowser.ExecWB(
8
,
1
)
>
426
</
p
>
427
<
p
>
<
input type
=
button value
=
打印预览 onclick
=
document.all.WebBrowser.ExecWB(
7
,
1
)
>
428
</
center
>
429
//
去掉打印时的页眉页脚
430
431
432
<
script language
=
"
JavaScript
"
>
433
var
HKEY_Root,HKEY_Path,HKEY_Key;
434HKEY_Root
=
"
HKEY_CURRENT_USER
"
;
435HKEY_Path
=
"
\\Software\\Microsoft\\Internet Explorer\\PageSetup\\
"
;
436
//
设置网页打印的页眉页脚为空
437
function
PageSetup_Null()
438
{
439
try
440
{
441
var
Wsh
=
new
ActiveXObject(
"
WScript.Shell
"
);
442
HKEY_Key
=
"
header
"
;
443
Wsh.RegWrite(HKEY_Root
+
HKEY_Path
+
HKEY_Key,
""
);
444
HKEY_Key
=
"
footer
"
;
445
Wsh.RegWrite(HKEY_Root
+
HKEY_Path
+
HKEY_Key,
""
);
446
}
447
catch
(e)
{}
448
}
449
//
设置网页打印的页眉页脚为默认值
450
function
PageSetup_Default()
451
{
452
try
453
{
454
var
Wsh
=
new
ActiveXObject(
"
WScript.Shell
"
);
455
HKEY_Key
=
"
header
"
;
456
Wsh.RegWrite(HKEY_Root
+
HKEY_Path
+
HKEY_Key,
"
&w&b页码,&p/&P
"
);
457
HKEY_Key
=
"
footer
"
;
458
Wsh.RegWrite(HKEY_Root
+
HKEY_Path
+
HKEY_Key,
"
&u&b&d
"
);
459
}
460
catch
(e)
{}
461
}
462
</
script
>
463
<
input type
=
"
button
"
value
=
"
清空页码
"
onclick
=
PageSetup_Null()
>
464
<
input type
=
"
button
"
value
=
"
恢复页码
"
onclick
=
PageSetup_Default()
>
465
//
浏览器验证
466
467
468
function
checkBrowser()
469
{
470
this
.ver
=
navigator.appVersion
471
this
.dom
=
document.getElementById
?
1
:
0
472
this
.ie6
=
(
this
.ver.indexOf(
"
MSIE 6
"
)
>-
1
&&
this
.dom)
?
1
:
0
;
473
this
.ie5
=
(
this
.ver.indexOf(
"
MSIE 5
"
)
>-
1
&&
this
.dom)
?
1
:
0
;
474
this
.ie4
=
(document.all
&&
!
this
.dom)
?
1
:
0
;
475
this
.ns5
=
(
this
.dom
&&
parseInt(
this
.ver)
>=
5
)
?
1
:
0
;
476
this
.ns4
=
(document.layers
&&
!
this
.dom)
?
1
:
0
;
477
this
.mac
=
(
this
.ver.indexOf('Mac')
>
-
1
)
?
1
:
0
;
478
this
.ope
=
(navigator.userAgent.indexOf('Opera')
>-
1
);
479
this
.ie
=
(
this
.ie6
||
this
.ie5
||
this
.ie4)
480
this
.ns
=
(
this
.ns4
||
this
.ns5)
481
this
.bw
=
(
this
.ie6
||
this
.ie5
||
this
.ie4
||
this
.ns5
||
this
.ns4
||
this
.mac
||
this
.ope)
482
this
.nbw
=
(
!
this
.bw)
483
return
this
;
484
}
485
//
计算内容宽和高
486
<
SCRIPT language
=
"
javascript
"
>
487
function
test(obj)
488
{
489
var
range
=
obj.createTextRange();
490
alert(
"
内容区宽度:
"
+
range.boundingWidth
491
+
"
px\r\n内容区高度:
"
+
range.boundingHeight
+
"
px
"
);
492
493
}
494
</
SCRIPT
>
495
<
BODY
>
496
<
Textarea id
=
"
txt
"
height
=
"
150
"
>
sdf
</
textarea
><
INPUT type
=
"
button
"
value
=
"
计算内容宽度
"
onClick
=
"
test(txt)
"
>
497
</
BODY
>
498
//
无模式的提示框
499
500
function
modelessAlert(Msg)
501
{
502
window.showModelessDialog(
"
javascript:alert(\
""
+escape(Msg)+
"
\
"
);window.close();
"
,
""
,
"
status:no;resizable:no;help:no;dialogHeight:height:30px;dialogHeight:40px;
"
);
503
}
504
505
506
507
508
509
510
511
512
//
屏蔽按键
513
514
515
<
html
>
516
<
head
>
517
<
meta http
-
equiv
=
"
Content-Type
"
content
=
"
text/html; charset=gb2312
"
>
518
<
noscript
><
meta http
-
equiv
=
"
refresh
"
content
=
"
0;url=about:noscript
"
></
noscript
>
519
<
title
>
屏蔽鼠标右键、Ctrl
+
N、Shift
+
F10、Alt
+
F4、F11、F5刷新、退格键
</
title
>
520
</
head
>
521
<
body
>
522
<
script language
=
"
Javascript
"
><!--
523
//
屏蔽鼠标右键、Ctrl+N、Shift+F10、F11、F5刷新、退格键
524
//
Author: meizz(梅花雨) 2002-6-18
525
function
document.oncontextmenu()
{event.returnValue
=
false
;}
//
屏蔽鼠标右键
526
function
window.onhelp()
{
return
false
}
//
屏蔽F1帮助
527
function
document.onkeydown()
528
{
529
if
((window.event.altKey)
&&
530
((window.event.keyCode
==
37
)
||
//
屏蔽 Alt+ 方向键 ←
531
(window.event.keyCode
==
39
)))
//
屏蔽 Alt+ 方向键 →
532
{
533
alert(
"
不准你使用ALT+方向键前进或后退网页!
"
);
534
event.returnValue
=
false
;
535
}
536
/**/
/**/
/**/
/*
注:这还不是真正地屏蔽 Alt+ 方向键,
537 因为 Alt+ 方向键弹出警告框时,按住 Alt 键不放,
538 用鼠标点掉警告框,这种屏蔽方法就失效了。以后若
539 有哪位高手有真正屏蔽 Alt 键的方法,请告知。
*/
540
if
((event.keyCode
==
8
)
||
//
屏蔽退格删除键
541
(event.keyCode
==
116
)
||
//
屏蔽 F5 刷新键
542
(event.ctrlKey
&&
event.keyCode
==
82
))
{
//
Ctrl + R
543
event.keyCode
=
0
;
544
event.returnValue
=
false
;
545
}
546
if
(event.keyCode
==
122
)
{event.keyCode
=
0
;event.returnValue
=
false
;}
//
屏蔽F11
547
if
(event.ctrlKey
&&
event.keyCode
==
78
) event.returnValue
=
false
;
//
屏蔽 Ctrl+n
548
if
(event.shiftKey
&&
event.keyCode
==
121
)event.returnValue
=
false
;
//
屏蔽 shift+F10
549
if
(window.event.srcElement.tagName
==
"
A
"
&&
window.event.shiftKey)
550
window.event.returnValue
=
false
;
//
屏蔽 shift 加鼠标左键新开一网页
551
if
((window.event.altKey)
&&
(window.event.keyCode
==
115
))
//
屏蔽Alt+F4
552
{
553
window.showModelessDialog(
"
about:blank
"
,
""
,
"
dialogWidth:1px;dialogheight:1px
"
);
554
return
false
;
555
}
556
}
557
</
script
>
558屏蔽鼠标右键、Ctrl
+
N、Shift
+
F10、Alt
+
F4、F11、F5刷新、退格键
559
</
body
>
560
</
html
>
561
//
屏蔽打印
562
<
style
>
563
@media print
{
564
*
{display:none}
565
}
566
</
style
>
567
568
//
移动的图层,拖动
569
570
5711
.
<
span style
=
'position:absolute;
200
;height:
200
;background:red' onmousedown
=
MouseDown(
this
) onmousemove
=
MouseMove() onmouseup
=
MouseUp()
>
meizz
</
span
>
572
<
script language
=
javascript
>
573
var
Obj;
574
function
MouseDown(obj)
575
{
576
Obj
=
obj;
577
Obj.setCapture();
578
Obj.l
=
event.x
-
Obj.style.pixelLeft;
579
Obj.t
=
event.y
-
Obj.style.pixelTop;
580
}
581
function
MouseMove()
582
{
583
if
(Obj
!=
null
)
584
{
585
Obj.style.left
=
event.x
-
Obj.l;
586
Obj.style.top
=
event.y
-
Obj.t;
587
}
588
}
589
function
MouseUp()
590
{
591
if
(Obj
!=
null
)
592
{
593
Obj.releaseCapture();
594
Obj
=
null
;
595
}
596
}
597
</
script
>
5982
.
599
<
div id
=
"
myDiv
"
src
=
"
logo.gif
"
ondrag
=
"
doDrag();
"
onmouseover
=
"
this.style.cursor='hand'
"
style
=
"
position:absolute;left=100;top=100;
"
onmousedown
=
"
doMouseDown();
"
>
600
<
a href
=
"
#
"
onclick
=
"
return false
"
><
h1
>
wlecome
</
h1
></
a
>
601
</
div
>
602
<
script language
=
"
JavaScript
"
type
=
"
text/javascript
"
>
603
var
orgMouseX;
604
var
orgMouseY;
605
var
orgObjX;
606
var
orgObjY;
607
function
doDrag()
608
{
609
var
myObject
=
document.all.myDiv;
610
611
var
x
=
event.clientX;
612
var
y
=
event.clientY;
613myObject.style.left
=
x
-
(orgMouseX
-
orgObjX);
614myObject.style.top
=
y
-
(orgMouseY
-
orgObjY);
615
616
}
617
function
doMouseDown()
618
{
619orgMouseX
=
event.clientX;
620orgMouseY
=
event.clientY;
621orgObjX
=
parseInt(document.all.myDiv.style.left);
622orgObjY
=
parseInt(document.all.myDiv.style.top);
623
}
624
625
</
script
>
626
627
//
文档状态改变
628
629
630
<
iframe src
=
"
a.html
"
id
=
"
f
"
name
=
"
f
"
scrolling
=
"
no
"
frameborder
=
0
marginwidth
=
0
marginheight
=
0
></
iframe
>
631
<
script
>
632
var
doc
=
window.frames[
"
f
"
].document;
633
function
s()
{
634
if
(doc.readyState
==
"
complete
"
)
{
635
document.all.f.style.height
=
doc.body.scrollHeight
636
document.all.f.style.width
=
doc.body.scrollWidth
637
}
638
}
639doc.onreadystatechange
=
s
640
</
script
>
641
642
//
刷新后不变的文本框
643
644
<
HTML
>
645
<
HEAD
>
646
<
META NAME
=
"
save
"
CONTENT
=
"
history
"
>
647
<
STYLE
>
648
.sHistory
{behavior:url(#
default
#savehistory);}
649
</
STYLE
>
650
</
HEAD
>
651
<
BODY
>
652
<
INPUT class
=
sHistory type
=
text id
=
oPersistInput
>
653
</
BODY
>
654
</
HTML
>
655
656
657
658
//
访问剪贴板
659
660
(
1
)拖拽访问
661event.dataTransfer.setData(
"
URL
"
, oImage.src);
662sImageURL
=
event.dataTransfer.getData(
"
URL
"
)
663
(
2
)普通访问
664window.clipboardData.setData(
"
Text
"
,oSource.innerText);
665window.clipboardData.getData(
"
Text
"
);
666
667
668
669
//
操作COOKIE
670
671
672
function
SetCookie(sName, sValue)
673
{
674
document.cookie
=
sName
+
"
=
"
+
escape(sValue)
+
"
;
"
;
675
}
676
function
GetCookie(sName)
677
{
678
var
aCookie
=
document.cookie.split(
"
;
"
);
679
for
(
var
i
=
0
; i
<
aCookie.length; i
++
)
680
{
681
682
var
aCrumb
=
aCookie[i].split(
"
=
"
);
683
if
(sName
==
aCrumb[
0
])
684
return
unescape(aCrumb[
1
]);
685
}
686
687
}
688
function
DelCookie(sName)
689
{
690document.cookie
=
sName
+
"
=
"
+
escape(sValue)
+
"
; expires=Fri, 31 Dec 1999 23:59:59 GMT;
"
;
691
}
692
//
setTimeout增加参数
693
694
<
script
>
695
var
_st
=
window.setTimeout;
696window.setTimeout
=
function
(fRef, mDelay)
{
697
if
(
typeof
fRef
==
'
function
')
{
698
var
argu
=
Array.prototype.slice.call(arguments,
2
);
699
var
f
=
(
function
()
{ fRef.apply(
null
, argu); }
);
700
return
_st(f, mDelay);
701
}
702
return
_st(fRef,mDelay);
703
}
704
function
test(x)
{
705
alert(x);
706
}
707window.setTimeout(test,
1000
,'fason');
708
</
script
>
709
710
//
自定义的apply,call
711
712Function.prototype.apply
=
function
(obj, argu)
{
713
if
(obj) obj.constructor.prototype._caller
=
this
;
714
var
argus
=
new
Array();
715
for
(
var
i
=
0
;i
<
argu.length;i
++
)
716
argus[i]
=
"
argu[
"
+
i
+
"
]
"
;
717
var
r;
718
eval(
"
r =
"
+
(obj
?
(
"
obj._caller(
"
+
argus.join(
"
,
"
)
+
"
);
"
) : (
"
this(
"
+
argus.join(
"
,
"
)
+
"
);
"
)));
719
return
r;
720
}
;
721Function.prototype.call
=
function
(obj)
{
722
var
argu
=
new
Array();
723
for
(
var
i
=
1
;i
<
arguments.length;i
++
)
724
argu[i
-
1
]
=
arguments[i];
725
return
this
.apply(obj, argu);
726
}
;
727
728
//
下载文件
729
730
function
DownURL(strRemoteURL,strLocalURL)
731
{
732
try
733
{
734
var
xmlHTTP
=
new
ActiveXObject(
"
Microsoft.XMLHTTP
"
);
735
xmlHTTP.open(
"
Get
"
,strRemoteURL,
false
);
736
xmlHTTP.send();
737
var
adodbStream
=
new
ActiveXObject(
"
ADODB.Stream
"
);
738
adodbStream.Type
=
1
;
//
1=adTypeBinary
739
adodbStream.Open();
740
adodbStream.write(xmlHTTP.responseBody);
741
adodbStream.SaveToFile(strLocalURL,
2
);
742
adodbStream.Close();
743
adodbStream
=
null
;
744
xmlHTTP
=
null
;
745
746
}
747
catch
(e)
748
{
749
window.confirm(
"
下载URL出错!
"
);
750
}
751
//
window.confirm("下载完成.");
752
}
753
754
//
检验连接是否有效
755
function
getXML(URL)
756
{
757
var
xmlhttp
=
new
ActiveXObject(
"
microsoft.xmlhttp
"
);
758
xmlhttp.Open(
"
GET
"
,URL,
false
);
759
try
760
{
761
xmlhttp.Send();
762
}
763
catch
(e)
{}
764
finally
765
{
766
var
result
=
xmlhttp.responseText;
767
if
(result)
768
{
769
if
(xmlhttp.Status
==
200
)
770
{
771
return
(
true
);
772
}
773
else
774
{
775
return
(
false
);
776
}
777
}
778
else
779
{
780
return
(
false
);
781
}
782
}
783
}
784
//
POST代替FORM
785
786
<
SCRIPT language
=
"
VBScript
"
>
787Function URLEncoding(vstrIn)
788
strReturn
=
""
789
For i
=
1
To Len(vstrIn)
790
ThisChr
=
Mid(vStrIn,i,
1
)
791
If Abs(Asc(ThisChr))
<
&
HFF Then
792
strReturn
=
strReturn
&
ThisChr
793
Else
794
innerCode
=
Asc(ThisChr)
795
If innerCode
<
0
Then
796
innerCode
=
innerCode
+
&
H10000
797
End If
798
Hight8
=
(innerCode And
&
HFF00)\
&
HFF
799
Low8
=
innerCode And
&
HFF
800
strReturn
=
strReturn
&
"
%
"
&
Hex(Hight8)
&
"
%
"
&
Hex(Low8)
801
End If
802
Next
803
URLEncoding
=
strReturn
804End Function
805Function bytes2BSTR(vIn)
806
strReturn
=
""
807
For i
=
1
To LenB(vIn)
808
ThisCharCode
=
AscB(MidB(vIn,i,
1
))
809
If ThisCharCode
<
&
H80 Then
810
strReturn
=
strReturn
&
Chr(ThisCharCode)
811
Else
812
NextCharCode
=
AscB(MidB(vIn,i
+
1
,
1
))
813
strReturn
=
strReturn
&
Chr(CLng(ThisCharCode)
*
&
H100
+
CInt(NextCharCode))
814
i
=
i
+
1
815
End If
816
Next
817
bytes2BSTR
=
strReturn
818End Function
819dim strA,oReq
820strA
=
URLEncoding(
"
submit1=Submit&text1=中文
"
)
821set oReq
=
CreateObject(
"
MSXML2.XMLHTTP
"
)
822oReq.open
"
POST
"
,
"
http://ServerName/VDir/TstResult.asp
"
,
false
823oReq.setRequestHeader
"
Content-Length
"
,Len(strA)
824oReq.setRequestHeader
"
CONTENT-TYPE
"
,
"
application/x-www-form-urlencoded
"
825oReq.send strA
826msgbox bytes2BSTR(oReq.responseBody)
827
</
SCRIPT
>
828
//
readyState是xmlhttp返回数据的进度,0=载入中,1=未初始化,2=已载入,3=运行中,4=完成
829
830
831
832
833
834
835
//
组件是否安装
836isComponentInstalled(
"
{6B053A4B-A7EC-4D3D-4567-B8FF8A1A5739}
"
,
"
componentID
"
))
837
838
//
检查网页是否存在
839
840
841
function
CheckURL(URL)
842
{
843
var
xmlhttp
=
new
ActiveXObject(
"
Microsoft.XMLHTTP
"
);
844
xmlhttp.Open(
"
GET
"
,URL,
false
);
845
try
846
{
847
xmlhttp.Send();
848
var
result
=
xmlhttp.status;
849
}
850
catch
(e)
{
return
(
false
); }
851
if
(result
==
200
)
852
{
853
return
true
;
854
}
855
xmlhttp
=
null
;
856
return
false
;
857
}
858
//
连接数据库
859
860
861
<
script language
=
"
javascript
"
>
862
//
用 JavaScript 写服务器端连接数据库的代码示例
863
var
conn
=
new
ActiveXObject(
"
ADODB.Connection
"
);
864
conn.Open(
"
Provider=SQLOLEDB.1; Data Source=localhost; User ID=sa;
"
865
+
"
Password=; Initial Catalog=pubs
"
);
866
var
rs
=
new
ActiveXObject(
"
ADODB.Recordset
"
);
867
var
sql
=
"
select * from authors
"
;
868
rs.open(sql, conn);
869
shtml
=
"
<table width='100%' border=1>
"
;
870
shtml
+=
"
<tr bgcolor='#f4f4f4'><td>au_id</td><td>au_lname</td><td>au_fname</td><td>phone</td><td>address</td><td> city</td><td>state</td><td>zip</td></tr>
"
;
871
while
(
!
rs.EOF)
872
{
873
shtml
+=
"
<tr><td>
"
+
rs(
"
au_id
"
)
+
"
</td><td>
"
+
rs(
"
au_lname
"
)
+
"
</td><td>
"
+
rs(
"
au_fname
"
)
+
"
</td><td>
"
+
rs(
"
phone
"
)
+
"
</td><td>
"
+
rs(
"
address
"
)
+
"
</td><td>
"
+
rs(
"
city
"
)
+
"
</td><td>
"
+
rs(
"
state
"
)
+
"
</td><td>
"
+
rs(
"
zip
"
)
+
"
</td></tr>
"
;
874
rs.moveNext;
875
}
876
shtml
+=
"
</table>
"
;
877
document.write(shtml);
878
rs.close();
879
rs
=
null
;
880
conn.close();
881
conn
=
null
;
882
</
script
>
883
//
使用数据岛
884
885
<
html
>
886
<
body
>
887srno:
<
input type
=
text datasrc
=
#xmldate DataFLD
=
srno size
=
"
76
"
><
BR
>
888times:
<
input type
=
text datasrc
=
#xmldate DataFLD
=
times size
=
"
76
"
><
BR
>
889
<
input id
=
"
first
"
TYPE
=
button value
=
"
<< 第一条记录
"
onclick
=
"
xmldate.recordset.moveFirst()
"
>
890
<
input id
=
"
prev
"
TYPE
=
button value
=
"
<上一条记录
"
onclick
=
"
xmldate.recordset.movePrevious()
"
>
891
<
input id
=
"
next
"
TYPE
=
button value
=
"
下一条记录>
"
onclick
=
"
xmldate.recordset.moveNext()
"
>
892
<
input id
=
"
last
"
TYPE
=
button value
=
"
最后一条记录>>
"
onclick
=
"
xmldate.recordset.moveLast()
"
>
893
<
input id
=
"
Add
"
TYPE
=
button value
=
"
添加新记录
"
onclick
=
"
xmldate.recordset.addNew()
"
>
894
895
<
XML ID
=
"
xmldate
"
>
896
<
infolist
>
897
<
info
><
srno
>
20041025
-
01
</
srno
><
times
>
null
</
times
></
info
>
898
<
info
><
srno
>
20041101
-
09
</
srno
><
times
>
2004年10月1日2点22分0秒
</
times
></
info
>
899
</
infolist
>
900
</
XML
>
901
</
body
>
902
</
html
>
903
//
获得参数
904
<
body
>
905
<
a href
=
"
javascript:location.href=location.href + '?a=1&b=2'
"
>
search
</
a
>
906
<
script language
=
"
JavaScript
"
>
907
<!--
908
var
a
=
location.search.substr(
1
);
909
if
(a.length
>
0
)
910
{
911
var
re
=
/
([
^&
]
*?
)\
=
([
^&
]
*
)
/
g
912
var
s
=
a.match(re);
913
for
(
var
i
=
0
;i
<
s.length;i
++
)
914
{
915
alert(s[i]);
916
alert(s[i].split(
"
=
"
)[
1
]);
917
}
918
}
919
//
-->
920
</
script
>
921
</
body
>
922
//
可编辑SELECT
923
924
<
input type
=
text name
=
re_name style
=
"
100px;height:21px;font-size:10pt;
"
><
span style
=
"
18px;border:0px solid red;
"
><
select name
=
"
r00
"
style
=
"
margin-left:-100px;118px; background-color:#FFEEEE;
"
onChange
=
"
document.all.re_name.value=this.value;
"
>
925
<
option value
=
"
1
"
>
11111111
<
option
>
926
<
option value
=
"
2
"
>
222222
</
option
>
927
<
option value
=
"
3
"
>
333333
</
option
>
928
</
select
>
929
</
span
>
930
931
932
933
934
935
936
937
//
设置光标位置
938
939
940
function
getCaret(textbox)
941
{
942
var
control
=
document.activeElement;
943
textbox.focus();
944
var
rang
=
document.selection.createRange();
945
rang.setEndPoint(
"
StartToStart
"
,textbox.createTextRange())
946
control.focus();
947
return
rang.text.length;
948
}
949
function
setCaret(textbox,pos)
950
{
951
try
952
{
953
var
r
=
textbox.createTextRange();
954
r.moveStart('character',pos);
955
r.collapse(
true
);
956
r.select();
957
}
958
catch
(e)
959
{}
960
}
961
function
selectLength(textbox,start,len)
962
{
963
try
964
{
965
var
r
=
textbox.createTextRange();
966
967
r.moveEnd('character',len
-
(textbox.value.length
-
start));
968
r.moveStart('character',start);
969
970
r.select();
971
}
972
catch
(e)
973
{
//
alert(e.description)}
974
}
975
function
insertAtCaret(textbox,text)
976
{
977
textbox.focus();
978
document.selection.createRange().text
=
text;
979
}
980
981
//
页内查找
982
983
984
function
findInPage(str)
985
{
986
var
txt, i, found,n
=
0
;
987
if
(str
==
""
)
988
{
989
return
false
;
990
}
991
txt
=
document.body.createTextRange();
992
for
(i
=
0
; i
<=
n
&&
(found
=
txt.findText(str))
!=
false
; i
++
)
993
{
994
txt.moveStart(
"
character
"
,
1
);
995
txt.moveEnd(
"
textedit
"
);
996
}
997
if
(found)
998
{
999
txt.moveStart(
"
character
"
,
-
1
);
1000
txt.findText(str);
1001
txt.select();
1002
txt.scrollIntoView();
1003
n
++
;
1004
}
1005
else
1006
{
1007
if
(n
>
0
)
1008
{
1009
n
=
0
;
1010
findInPage(str);
1011
}
1012
else
1013
{
1014
alert(str
+
"
您要找的文字不存在。\n \n请试着输入页面中的关键字再次查找!
"
);
1015
}
1016
}
1017
return
false
;
1018
}
1019
//
书
1020
1021http:
//
www.itpub.net/attachment.php?s=&postid=1894598
1022http:
//
www.wrclub.net/down/listdown.aspx?id=1341
1023
//
操作EXECL
1024
1025
<
script language
=
"
javascript
"
>
1026
function
jStartExcel()
{
1027
var
xls
=
new
ActiveXObject (
"
Excel.Application
"
);
1028
xls.visible
=
true
;
1029
var
newBook
=
xls.Workbooks.Add;
1030
newBook.Worksheets.Add;
1031
newBook.Worksheets(
1
).Activate;
1032
xls.ActiveWorkBook.ActiveSheet.PageSetup.Orientation
=
2
;
1033
xls.ActiveWorkBook.ActiveSheet.PageSetup.PaperSize
=
5
;
1034
newBook.Worksheets(
1
).Columns(
"
A
"
).columnwidth
=
50
;
1035
newBook.Worksheets(
1
).Columns(
"
A
"
).WrapText
=
true
;
1036
newBook.Worksheets(
1
).Columns(
"
B
"
).columnwidth
=
50
;
1037
newBook.Worksheets(
1
).Columns(
"
B
"
).WrapText
=
true
;
1038
newBook.Worksheets(
1
).Range(
"
A1:B1000
"
).NumberFormat
=
"
0
"
;
1039
newBook.Worksheets(
1
).Range(
"
A1:B1000
"
).HorizontalAlignment
=
-
4131
;
1040
newBook.Worksheets(
1
).Cells(
1
,
1
).Interior.ColorIndex
=
"
15
"
;
1041
newBook.Worksheets(
1
).Cells(
1
,
1
).value
=
"
First Column, First Cell
"
;
1042
newBook.Worksheets(
1
).Cells(
2
,
1
).value
=
"
First Column, Second Cell
"
;
1043
newBook.Worksheets(
1
).Cells(
1
,
2
).value
=
"
Second Column, First Cell
"
;
1044
newBook.Worksheets(
1
).Cells(
2
,
2
).value
=
"
Second Column, Second Cell
"
;
1045
newBook.Worksheets(
1
).Name
=
"
My First WorkSheet
"
;
1046
}
1047
</
script
>
1048
1049
//
自定义提示条
1050
1051
1052
<
a href
=
"
#
"
title
=
"
这是提示
"
>
tip
</
a
>
1053
<
script Language
=
"
JavaScript
"
>
1054
//
***********默认设置定义.*********************
1055tPopWait
=
50
;
//
停留tWait豪秒后显示提示。
1056tPopShow
=
5000
;
//
显示tShow豪秒后关闭提示
1057showPopStep
=
20
;
1058popOpacity
=
99
;
1059
//
***************内部变量定义*****************
1060sPop
=
null
;
1061curShow
=
null
;
1062tFadeOut
=
null
;
1063tFadeIn
=
null
;
1064tFadeWaiting
=
null
;
1065document.write(
"
<style type='text/css'id='defaultPopStyle'>
"
);
1066document.write(
"
.cPopText { background-color: #F8F8F5;color:#000000; border: 1px #000000 solid;font-color: font-size: 12px; padding-right: 4px; padding-left: 4px; height: 20px; padding-top: 2px; padding-bottom: 2px; filter: Alpha(Opacity=0)}
"
);
1067document.write(
"
</style>
"
);
1068document.write(
"
<div id='dypopLayer' style='position:absolute;z-index:1000;' class='cPopText'></div>
"
);
1069
1070
function
showPopupText()
{
1071
var
o
=
event.srcElement;
1072MouseX
=
event.x;
1073MouseY
=
event.y;
1074
if
(o.alt
!=
null
&&
o.alt
!=
""
)
{o.dypop
=
o.alt;o.alt
=
""
}
;
1075
if
(o.title
!=
null
&&
o.title
!=
""
)
{o.dypop
=
o.title;o.title
=
""
}
;
1076
if
(o.dypop
!=
sPop)
{
1077sPop
=
o.dypop;
1078clearTimeout(curShow);
1079clearTimeout(tFadeOut);
1080clearTimeout(tFadeIn);
1081clearTimeout(tFadeWaiting);
1082
if
(sPop
==
null
||
sPop
==
""
)
{
1083dypopLayer.innerHTML
=
""
;
1084dypopLayer.style.filter
=
"
Alpha()
"
;
1085dypopLayer.filters.Alpha.opacity
=
0
;
1086
}
1087
else
{
1088
if
(o.dyclass
!=
null
) popStyle
=
o.dyclass
1089
else
popStyle
=
"
cPopText
"
;
1090curShow
=
setTimeout(
"
showIt()
"
,tPopWait);
1091
}
1092
}
1093
}
1094
function
showIt()
{
1095dypopLayer.className
=
popStyle;
1096dypopLayer.innerHTML
=
sPop;
1097popWidth
=
dypopLayer.clientWidth;
1098popHeight
=
dypopLayer.clientHeight;
1099
if
(MouseX
+
12
+
popWidth
>
document.body.clientWidth) popLeftAdjust
=-
popWidth
-
24
1100
else
popLeftAdjust
=
0
;
1101
if
(MouseY
+
12
+
popHeight
>
document.body.clientHeight) popTopAdjust
=-
popHeight
-
24
1102
else
popTopAdjust
=
0
;
1103dypopLayer.style.left
=
MouseX
+
12
+
document.body.scrollLeft
+
popLeftAdjust;
1104dypopLayer.style.top
=
MouseY
+
12
+
document.body.scrollTop
+
popTopAdjust;
1105dypopLayer.style.filter
=
"
Alpha(Opacity=0)
"
;
1106fadeOut();
1107
}
1108
function
fadeOut()
{
1109
if
(dypopLayer.filters.Alpha.opacity
<
popOpacity)
{
1110dypopLayer.filters.Alpha.opacity
+=
showPopStep;
1111tFadeOut
=
setTimeout(
"
fadeOut()
"
,
1
);
1112
}
1113
else
{
1114dypopLayer.filters.Alpha.opacity
=
popOpacity;
1115tFadeWaiting
=
setTimeout(
"
fadeIn()
"
,tPopShow);
1116
}
1117
}
1118
function
fadeIn()
{
1119
if
(dypopLayer.filters.Alpha.opacity
>
0
)
{
1120dypopLayer.filters.Alpha.opacity
-=
1
;
1121tFadeIn
=
setTimeout(
"
fadeIn()
"
,
1
);
1122
}
1123
}
1124document.onmouseover
=
showPopupText;
1125
</
script
>
1126
//
插入文字
1127
1128document.onclick
=
function
()
{
1129
var
oSource
=
window.event.srcElement;
1130
if
(oSource.tagName
!=
"
DIV
"
)
1131
return
false
;
1132
var
sel
=
document.selection;
1133
if
(sel
!=
null
)
{
1134
var
rng
=
sel.createRange();
1135
if
(rng
!=
null
)
1136rng.pasteHTML(
"
<font color=red>插入文字</font>
"
);
1137
}
1138
}
1139
//
netscapte下操作xml
1140
1141doc
=
new
ActiveXObject(
"
Msxml2.DOMDocument
"
);
1142doc
=
new
ActiveXObject(
"
Microsoft.XMLDOM
"
)
1143
->>
1144doc
=
(
new
DOMParser()).parseFromString(sXML,'text
/
xml')
1145
1146
1147
1148
//
判断键值
1149
1150
<
html
>
1151
<
meta http
-
equiv
=
"
Content-Type
"
content
=
"
text/html; charset=gb2312
"
>
1152
<
head
>
1153
<
script language
=
"
javascript
"
>
1154
var
ie
=
navigator.appName
==
"
Microsoft Internet Explorer
"
?
true
:
false
;
1155
1156
function
keyDown(e)
1157
{
1158
if
(
!
ie)
1159
{
1160
var
nkey
=
e.which;
1161
var
iekey
=
'现在是ns浏览器';
1162
var
realkey
=
String.fromCharCode(e.which);
1163
}
1164
if
(ie)
1165
{
1166
var
iekey
=
event.keyCode;
1167
var
nkey
=
'现在是ie浏览器';
1168
var
realkey
=
String.fromCharCode(event.keyCode);
1169
if
(event.keyCode
==
32
)
{realkey
=
'\' 空格\''}
1170
if
(event.keyCode
==
13
)
{realkey
=
'\' 回车\''}
1171
if
(event.keyCode
==
27
)
{realkey
=
'\' Esc\''}
1172
if
(event.keyCode
==
16
)
{realkey
=
'\' Shift\''}
1173
if
(event.keyCode
==
17
)
{realkey
=
'\' Ctrl\''}
1174
if
(event.keyCode
==
18
)
{realkey
=
'\' Alt\''}
1175
}
1176
alert('ns浏览器中键值:'
+
nkey
+
'\n'
+
'ie浏览器中键值:'
+
iekey
+
'\n'
+
'实际键为'
+
realkey);
1177
}
1178document.onkeydown
=
keyDown;
1179
</
script
>
1180
</
head
>
1181
<
body
>
1182
//
Javascript Document.
1183
<
hr
>
1184
<
center
>
1185
<
h3
>
请按任意一个键。。。。
</
h3
>
1186
</
center
>
1187
</
body
>
1188
</
html
>
1189
1190
1191
1192
//
禁止FSO
1193
1194
11951
.注销组件
1196regsvr32
/
u scrrun.dll
11972
.修改PROGID
1198HKEY_CLASSES_ROOT\Scripting.FileSystemObject
1199Scripting.FileSystemObject
12003
.对于使用object的用户,修改HKEY_CLASSES_ROOT\Scripting.
1201
1202
//
省略号
1203
1204
<
DIV STYLE
=
"
120px; height: 50px; border: 1px solid blue;
1205 overflow: hidden; text-overflow:ellipsis
"
>
1206
<
NOBR
>
就是比如有一行文字,很长,表格内一行显示不下.
</
NOBR
>
1207
</
DIV
>
1208
1209
1210
1211
//
检测media play版本
1212
1213
<
IE:clientCaps ID
=
"
oClientCaps
"
style
=
"
{behavior:url(#default#clientcaps)}
"
/>
1214
<
SCRIPT
>
1215
var
flash
=
""
;
1216
WMPVersion
=
oClientCaps.getComponentVersion(
"
{22D6F312-B0F6-11D0-94AB-0080C74C7E95}
"
,
"
ComponentID
"
);
1217
if
(WMPVersion
!=
""
)
{
1218
flash
=
""
;
1219
var
version
=
WMPVersion.split(
"
,
"
);
1220
var
i;
1221
for
(i
=
0
; i
<
version.length; i
++
)
{
1222
if
(i
!=
0
)
1223
flash
+=
"
.
"
;
1224
flash
+=
version[i];
1225
}
1226
document.write(
"
您的Windows Media Player 版本是:
"
+
flash
+
"
<p>
"
);
1227
}
1228
</
SCRIPT
>
1229
1230
1231
1232
1233
//
图象按比例
1234
1235
<
script language
=
"
JavaScript
"
>
1236
<!--
1237
//
图片按比例缩放
1238
var
flag
=
false
;
1239
function
DrawImage(ImgD)
{
1240
var
image
=
new
Image();
1241
var
iwidth
=
80
;
//
定义允许图片宽度
1242
var
iheight
=
80
;
//
定义允许图片高度
1243
image.src
=
ImgD.src;
1244
if
(image.width
>
0
&&
image.height
>
0
)
{
1245
flag
=
true
;
1246
if
(image.width
/
image.height
>=
iwidth
/
iheight)
{
1247
if
(image.width
>
iwidth)
{
1248
ImgD.width
=
iwidth;
1249
ImgD.height
=
(image.height
*
iwidth)
/
image.width;
1250
}
else
{
1251
ImgD.width
=
image.width;
1252
ImgD.height
=
image.height;
1253
}
1254
ImgD.alt
=
image.width
+
"
×
"
+
image.height;
1255
}
1256
else
{
1257
if
(image.height
>
iheight)
{
1258
ImgD.height
=
iheight;
1259
ImgD.width
=
(image.width
*
iheight)
/
image.height;
1260
}
else
{
1261
ImgD.width
=
image.width;
1262
ImgD.height
=
image.height;
1263
}
1264
ImgD.alt
=
image.width
+
"
×
"
+
image.height;
1265
}
1266
}
1267
}
1268
//
-->
1269
</
script
>
1270
<
img src
=
"
..
"
onload
=
"
DrawImage(this)
"
>
1271
1272
1273
1274
1275
//
细线SELECT
1276
1277
<
span style
=
"
border:1px solid #000000; position:absolute; overflow:hidden;
"
>
1278
<
select style
=
"
margin:-2px;
"
>
1279
<
option
>
1111
</
option
>
1280
<
option
>
11111111111111
</
option
>
1281
<
option
>
111111111
</
option
>
1282
</
select
></
span
>
1283
1284
//
Import
1285
1286
function
Import()
{
1287
for
(
var
i
=
0
; i
<
arguments.length; i
++
)
{
1288
var
file
=
arguments[i];
1289
if
( file.match(
/
\.js$
/
i))
1290
document.write('
<
script type
=
\
"
text/javascript\
"
src
=
\
"
' + file + '\
"
></
sc'
+
'ript
>
');
1291
else
1292
document.write('
<
style type
=
\
"
text/css\
"
>
@import \
"
' + file + '\
"
;
</
style
>
');
1293
}
1294
}
;
1295
1296
//
js枚举
1297
1298
1299
1300
function
getComputerName()
1301
{
1302
var
objWMIService
=
GetObject(
"
Winmgmts:root\cimv2
"
);
1303
for
(e
=
new
Enumerator(objWMIService) ;
!
e.atEnd() ; e.moveNext())
1304
{
1305
var
getComputer
=
e.item();
1306
return
getComputer.Name;
1307
}
1308
}
1309
1310
1311
//
条件编译
1312
1313
1314
<
script language
=
javascript
>
1315
/**/
/**/
/**/
/*
@cc_on @
*/
1316
/**/
/**/
/**/
/*
@if (@_win32 && @_jscript_version>5)
1317function window.confirm(str)
1318{
1319 execScript("n = msgbox('"+ str +"', 257)", "vbscript");
1320 return(n == 1);
1321}
1322@end @
*/
1323
</
script
>
1324
1325
1326
//
取得innerText
1327
1328
1329
1330
<
SCRIPT LANGUAGE
=
"
JavaScript
"
>
1331
<!--
1332
var
xmlDoc
=
new
ActiveXObject(
"
Msxml2.DOMDocument.4.0
"
);
1333
var
currNode;
1334
xmlDoc.async
=
false
;
1335
xmlDoc.async
=
false
;
1336
xmlDoc.loadXML(
"
<TABLENAME> 你好你阿三 大法 司法等四 </TABLENAME>
"
);
1337
currNode
=
xmlDoc.documentElement;
1338
1339
var
s
=
currNode.xml;
1340
var
r
=
/
\
<
([
^
\
>
\s]
*?
)[
^
\
>
]
*?
\
>
([
^
\
<
]
*?
)\
<
\
/
\
1
\
>/
1341
var
b
=
s.replace(r,
"
$2
"
);
1342
alert(b);
1343
//
-->
1344
</
SCRIPT
>
1345
//
mergeAttributes 复制所有读/写标签属性到指定元素。
1346
1347
<
SCRIPT
>
1348
function
fnMerge()
{
1349oSource.children[
1
].mergeAttributes(oSource.children[
0
]);
1350
}
1351
</
SCRIPT
>
1352
<
SPAN ID
=
oSource
>
1353
<
DIV
1354ID
=
"
oDiv
"
1355ATTRIBUTE1
=
"
true
"
1356ATTRIBUTE2
=
"
true
"
1357onclick
=
"
alert('click');
"
1358onmouseover
=
"
this.style.color='#0000FF';
"
1359onmouseout
=
"
this.style.color='#000000';
"
1360
>
1361This is a sample
<
B
>
DIV
</
B
>
element.
1362
</
DIV
>
1363
<
DIV ID
=
"
oDiv2
"
>
1364This is another sample
<
B
>
DIV
</
B
>
element.
1365
</
DIV
>
1366
</
SPAN
>
1367
<
INPUT
1368TYPE
=
"
button
"
1369VALUE
=
"
Merge Attributes
"
1370onclick
=
"
fnMerge()
"
1371
>
查看全文
相关阅读:
Nginx 高级配置
nginx安装和优化配置
location语法介绍
iptables
通过 loganalyzer 展示数据库中的系统日志
ubuntu_server16.04详细安装步骤
内存控制mmap的原型和使用方法
C语言中open函数read函数lseek函数是如何使用的
gdb调试工具的基本使用
C语言如何制作静态库
原文地址:https://www.cnblogs.com/conquer/p/833996.html
最新文章
纵论物联网
Android Bitmap占用内存计算公式
Android Activity生命周期与启动模式
Java 引用
Java 垃圾回收
Java ThreadLocal
Java 线程池
CentOs7配置java开发环境
分布式系统环境搭建
Win10专业版激活方法
热门文章
微服务相关命令
MySql 部分字段去重
Centos7.6 Mysql数据库自动备份配置
【E20200105-1】Centos 7.x 下vsftpd配置文件常用配置详解
【E20200102-1】centos 7 下vsftp的安装和配置
【E20200101-1】Centos 7.x 关闭防火墙(firewall)和SELinux
Zabbix-部署
redis主要配置项
编译安装redis
Nginx Rewrite相关功能
Copyright © 2011-2022 走看看