1.
2.事件源對象
3.event.srcElement.tagName
4.event.srcElement.type
5.捕獲釋放
6.event.srcElement.setCapture();
7.event.srcElement.releaseCapture();
8.事件按鍵
9.event.keyCode
10.event.shiftKey
11.event.altKey
12.event.ctrlKey
13.事件返回值
14.event.returnValue
15.鼠標(biāo)位置
16.event.x
17.event.y
18.窗體活動元素
19.document.activeElement
20.綁定事件
21.document.captureEvents(Event.KEYDOWN);
22.訪問窗體元素
23.document.all("txt").focus();
24.document.all("txt").select();
25.窗體命令
26.document.execCommand
27.窗體COOKIE
28.document.cookie
29.菜單事件
30.document.oncontextmenu
31.創(chuàng)建元素
32.document.createElement("SPAN");
33.根據(jù)鼠標(biāo)獲得元素:
34.document.elementFromPoint(event.x,event.y).tagName=="TD
35.document.elementFromPoint(event.x,event.y).appendChild(ms)
36.窗體圖片
37.document.images[索引]
38.窗體事件綁定
39.document.onmousedown=scrollwindow;
40.元素
41.document.窗體.elements[索引]
42.對象綁定事件
43.document.all.xxx.detachEvent('onclick',a);
44.插件數(shù)目
45.navigator.plugins
46.取變量類型
47.typeof($js_libpath) =="undefined"
48.下拉框
49.下拉框.options[索引]
50.下拉框.options.length
51.查找對象
52.document.getElementsByName("r1");
53.document.getElementById(id);
54.定時
55.timer=setInterval('scrollwindow()',delay);
56.clearInterval(timer);
57.UNCODE編碼
58.escape() ,unescape
59.父對象
60.obj.parentElement(dhtml)
61.obj.parentNode(dom)
62.交換表的行
63.TableID.moveRow(2,1)
64.替換CSS
65.document.all.csss.href = "a.css";
66.并排顯示
67.display:inline
68.隱藏焦點(diǎn)
69.hidefocus=true
70.根據(jù)寬度換行
71.style="word-break:break-all"
72.自動刷新
73.<meta HTTP-EQUIV="refresh" CONTENT="8;URL=http://c98.yeah.net">
74.簡單郵件
75.<a href="mailto:aaa@bbb.com?subject=ccc&body=xxxyyy">
76.快速轉(zhuǎn)到位置
77.obj.scrollIntoView(true)
78.錨
79.<a name="first">
80.<a href="#first">anchors</a>
81.網(wǎng)頁傳遞參數(shù)
82.location.search();
83.可編輯
84.obj.contenteditable=true
85.執(zhí)行菜單命令
86.obj.execCommand
87.雙字節(jié)字符
88./[^\x00-\xff]/
89.漢字
90./[\u4e00-\u9fa5]/
91.讓英文字符串超出表格寬度自動換行
92.word-wrap: break-word; word-break: break-all;
93.透明背景
94.<IFRAME src="1.htm" width=300 height=180 allowtransparency></iframe>
95.獲得style內(nèi)容
96.obj.style.cssText
97.HTML標(biāo)簽
98.document.documentElement.innerHTML
99.第一個style標(biāo)簽
100.document.styleSheets[0]
101.style標(biāo)簽里的第一個樣式
102.document.styleSheets[0].rules[0]
103.防止點(diǎn)擊空鏈接時,頁面往往重置到頁首端。
104.<a href="BLOCKED SCRIPTfunction()">word</a>
105.上一網(wǎng)頁源
106.asp:
107.request.servervariables("HTTP_REFERER")
108.BLOCKED SCRIPT
109.document.referrer
110.釋放內(nèi)存
111.CollectGarbage();
112.禁止右鍵
113.document.oncontextmenu = function() { return false;}
114.禁止保存
115.<noscript><iframe src="*.htm"></iframe></noscript>
116.禁止選取<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()>
117.禁止粘貼
118.<input type=text onpaste="returnfalse">
119.地址欄圖標(biāo)
120.<link rel="Shortcut Icon" href="favicon.ico">
121.favicon.ico 名字最好不變16*16的16色,放虛擬目錄根目錄下
122.收藏欄圖標(biāo)
123.<link rel="Bookmark" href="favicon.ico">
124.查看源碼
125.<input type=button value=查看網(wǎng)頁源代碼 onclick="window.location= 'view-source:'+ 'http://www.csdn.net/'">
126.關(guān)閉輸入法
127.<input style="ime-mode:disabled">
128.自動全選
129.<input type=text name=text1 value="123" onfocus="this.select()">
130.ENTER鍵可以讓光標(biāo)移到下一個輸入框
131.<input onkeydown="if(event.keyCode==13)event.keyCode=9">
132.文本框的默認(rèn)值
133.<input type=text value="123" onfocus="alert(this.defaultValue)">
134.title換行
135.obj.title = "123
sdfs "
136.獲得時間所代表的微秒
137.var n1 = new Date("2004-10-10".replace(/-/g,"\/")).getTime()
138.窗口是否關(guān)閉
139.win.closed
140.checkbox扁平
141.<input type=checkbox style="position: absolute; clip:rect(5px 15px 15px 5px)"><br>
142.獲取選中內(nèi)容
143.document.selection.createRange().duplicate().text
144.自動完成功能
145.<input type=text autocomplete=on>打開該功能
146.<input type=text autocomplete=off>關(guān)閉該功能
147.窗口最大化
148.<body onload="window.resizeTo(window.screen.width - 4,window.screen.height-50);window.moveTo(-4,-4)">
149.無關(guān)閉按鈕IE
150.window.open("aa.htm", "meizz","fullscreen=7");
151.統(tǒng)一編碼/解碼
152.alert(decodeURIComponent(encodeURIComponent("http://你好.com?as= hehe")))
153.encodeURIComponent對":"、"/"、";" 和 "?"也編碼
154.表格行指示
155.<tr onmouseover="this.bgColor='#f0f0f0'" onmouseout="this.bgColor='#ffffff'">
156.
157.1.文本框焦點(diǎn)問題
158.onBlur:當(dāng)失去輸入焦點(diǎn)后產(chǎn)生該事件
159.onFocus:當(dāng)輸入獲得焦點(diǎn)后,產(chǎn)生該文件
160.Onchange:當(dāng)文字值改變時,產(chǎn)生該事件
161.Onselect:當(dāng)文字加亮后,產(chǎn)生該文件
162.<input type="text" value="郭強(qiáng)" onfocus="if(value=='郭強(qiáng)') {value=''}" onblur="if
163.(value=='') {value='郭強(qiáng)'}">點(diǎn)擊時文字消失,失去焦點(diǎn)時文字再出現(xiàn)
164.2.網(wǎng)頁按鈕的特殊顏色
165.<input type=button name="Submit1" value="郭強(qiáng)" size=10 class=s02
166.style="background-color:rgb(235,207,22)">
167.3.鼠標(biāo)移入移出時顏色變化
168.<input type="submit" value="找吧"name="B1" onMouseOut=this.style.color="blue"
169.onMouseOver=this.style.color="red" class="button">
170.4.平面按鈕
171.<input type=submit value=訂閱 style="border:1px solid :#666666; height:17px; width:25pt;
172.BACKGROUND-COLOR: #E8E8FF; color:#666666" name="submit">
173.5.按鈕顏色變化
174.<input type=text name="nick" style="border:1px solid#666666; height:17px;
175.BACKGROUND-COLOR: #F4F4FF; color:#ff6600" size="15" maxlength="16">
176.6.平面輸入框
177.<input type="text" name="T1" size="20" style="border-style: solid; border-width: 1">
178.7.使窗口變成指定的大小
179.<script>
180.window.resizeTo(300,283);
181.</script>
182.8.使文字上下滾動
183.<marquee direction=up scrollamount=1 scrolldelay=100 onmouseover='this.stop()' onmouseout='this.start()'
184.height=60>
185.<!-- head_scrolltext -->
186.<tr>
187.<td>
188.共和國
189.</table> <!-- end head_scrolltext -->
190.</marquee>
191.9.狀態(tài)欄顯示該頁狀態(tài)
192.<base onmouseover="window.status='網(wǎng)站建設(shè) http://www.webmake.cn/ ';return true">
193.10.可以點(diǎn)擊文字實現(xiàn)radio選項的選定
194.<br>
195. <input type="radio" name="regtype" value="A03" id="A03">
196.<label for="A03"> 情侶 : 一次注冊兩個帳戶</label> <br>
197.11.可以在文字域的font寫onclick事件
198.12.打印</a>打印網(wǎng)頁
199.<a href='javascript:window.print ()'>
200.13.線型輸入框
201.<input type="text" name="key" size="12" value="關(guān)鍵字" onFocus=this.select() onMouseOver=this.focus()
202.class="line">
203.14.顯示文檔最后修改日期
204.<script language=javascript>
205.function hi(str)
206.{
207.document.write(document.lastModified)
208.alert("hi"+str+"!")
209.}
210.</script>
211.15.可以在鼠標(biāo)移到文字上時就觸發(fā)事件
212.<html>
213.<head>
214.<script language="LiveScript">
215.<!-- Hiding
216. function hello() {
217. alert("哈羅!");
218. }
219.</script>
220.</head>
221.<body>
222.<a href="" onMouseOver="hello()">link</a>
223.</body>
224.</html>
225.16.可以根據(jù)網(wǎng)頁上的選項來確定頁面顏色
226.<HTML>
227.<HEAD>
228.<TITLE>background.html</TITLE>
229.</HEAD>
230.<SCRIPT>
231.<!--
232.function bgChange(selObj) {
233.newColor = selObj.options[selObj.selectedIndex].text;
234.document.bgColor = newColor;
235.selObj.selectedIndex = -1;
236.}
237.//-->
238.</SCRIPT>
239.<BODY STYLE="font-family:Arial">
240.<B>Changing Background Colors</B>
241.<BR>
242.<FORM>
243. <SELECT SIZE="8" onChange="bgChange(this);">
244. <OPTION>Red
245. <OPTION>Orange
246. <OPTION>Yellow
247. <OPTION>Green
248. <OPTION>Blue
249. <OPTION>Indigo
250. <OPTION>Violet
251. <OPTION>White
252.<OPTION>pink
253. </SELECT>
254.</FORM>
255.</BODY>
256.</HTML>
257.17.將按鈕的特征改變
258.<style type="text/CSS">
259.<!--
260..style1 { background: #CCCCFF; border-width: thin thin thin thin; border-color: #CCCCFF
261.#CCCCCC #CCCCCC #CCCCFF}
262..style2 { font-weight: bold; background:#CCFFCC; border-width: thin medium medium thin;
263.border-color: #CCFF99 #999999#999999 #CCFF99}
264.-->
265.</style>
266. 本例按鈕的代碼如下:
267.<input type="submit" name="Submit" value="提 交" onmouseover="this.className='style2'"
268.onmouseout="this.className='style1'" class="style1">
269.18.改變按鈕的圖片.
270.<style type="text/css">
271.<!--
272..style3 { background: url(image/buttonbg1.gif); border: 0px; width: 60px; height: 22px}
273..style4 { font-weight: bold; background: url(image/buttonbg2.gif); border: 0px 0; width:
274.60px; height: 22px}
275.-->
276.</style>
277. 本例的按鈕代碼如下:
278.<input type="submit" name="Submit2" value="提 交" onmouseover="this.className='style4'"
279.onmouseout="this.className='style3'" class="style3">
280.19.打印頁面
281.<div align="center"><a class=content href="javascript:doPrint();">打印本稿</a></div>
282.20.可以直接寫html語言
283.document.write("");
284.21.改變下拉框的顏色
285.<select name="classid"
286.onChange="changelocation(document.myform.classid.options[document.myform.classid.selectedIndex].value)"
287.size="1" style="color:#008080;font-size: 14px">
288.22.轉(zhuǎn)至目標(biāo)URL
289.window.location="http://guoguo"
290.23.傳遞該object的form
291.UpdateSN('guoqiang99267',this.form)
292.function UpdateSN(strValue,strForm)
293.{
294. strForm.SignInName.value = strValue;
295. return false;
296.}
297.24.文字標(biāo)簽
298.<label for="AltName4"><input name="AltName" type="RADIO" tabindex="931" id="AltName4"
299.>guoqiang99859</label>
300.25.layer2為組件的ID,可以控制組件是否可見
301.document.all.item('Layer2').style.display = "block";
302.document.all.item('Layer2').style.display = "none";//
303.26.將頁面加入favorite中
304.<script language=javascript>
305.<!--
306.function Addme(){
307.url = "http://your.site.address"; //你自己的主頁地址
308.title = "Your Site Name"; //你自己的主頁名稱
309.window.external.AddFavorite(url,title);
310.-->
311.</script>//
312.27.過10秒自動關(guān)閉頁面
313.< script language="JavaScript" >
314.function closeit() {
315.setTimeout("self.close()",10000)
316.}
317.< /script >
318.28.可以比較字符的大小
319.char=post.charAt(i);
320.if(!('0'<=char&&char<='9'))
321.29.將字符轉(zhuǎn)化為數(shù)字
322.month = parseInt(char)
323.30.點(diǎn)擊value非空的選項時轉(zhuǎn)向指定連接
324.<select onchange='if(this.value!="")window.open(this.value)' class="textinput">
325. <option selected>主辦單位</option>
326. <option>-----------------</option>
327. <option value="http://www.bjd.com.cn/">北京日報</option>
328. <option value="http://www.ben.com.cn/">北京晚報</option>
329.</select>
330.31.改變背景顏色
331.<td width=* class=dp bgColor=#FAFBFC onmouseover="this.bgColor='#FFFFFF';"
332.onmouseout="this.bgColor='#FAFBFC';">
333.32.改變文字輸入框的背景顏色
334.<style>
335..input2 {background-image: url('../images/inputbg.gif'); background-color:
336.#D0DABB;border-top-width:1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}
337.</style>
338.<input name=content type=text size="47" class="input2" maxlength="50">
339.33.改變水平線的特征
340.<hr size="0" noshade color="#C0C0C0">
341.34.傳遞參數(shù)的方式
342.<a href="vote.asp?CurPage=8&id=3488">8</a>
343.35.頁內(nèi)跳轉(zhuǎn)
344.<a href="#1">1</a>
345.<a href="#2">2</a>
346.<a href="#3">3</a>
347.<a href="#4">4</a>
348.<a href="#5">5</a>
349.<a href="#6">6</a>
350.<a href="#7">7</a>
351.<a name="1">dfdf</a>
352.<a name="2">dfdf</a>//
353.36.兩個按鍵一起按下
354.if(event.ctrlKey && window.event.keyCode==13)//
355.37.刷新頁面
356.javascript:this.location.reload()//
357.38.將網(wǎng)頁的按鈕使能
358.<SCRIPT LANGUAGE="JavaScript">
359.function haha()
360.{
361.for(var i=0;i<document.form1.elements.length;i++)
362.{
363. if(document.form1.elements .name.indexOf("bb")!=-1)
364. document.form1.elements .disabled=!document.form1.elements .disabled;
365.}
366.}
367.</SCRIPT>
368.<BODY><form name=form1>
369.<INPUT TYPE="button" NAME="aa" value=cindy onclick=haha()>
370.<INPUT TYPE="button" NAME="bb " value=guoguo>
371.<INPUT TYPE="button" NAME="bb " value=guoguo>
372.39.文字移動
373.<marquee scrollamount=3 onmouseover=this.stop(); onmouseout=this.start();>
374.40.雙擊網(wǎng)頁自動跑
375.<SCRIPT LANGUAGE="JavaScript">
376.var currentpos,timer;
377.function initialize()
378.{
379.timer=setInterval("scrollwindow()",1);
380.}
381.function sc()
382.{
383.clearInterval(timer);
384.}
385.function scrollwindow()
386.{
387.currentpos=document.body.scrollTop;
388.window.scroll(0,++currentpos);
389.if (currentpos != document.body.scrollTop)
390. sc();
391.}
392.document.onmousedown=sc
393.document.ondblclick=initialize
394.</SCRIPT>//
395.41.后退
396.<INPUT TYPE="button" onclick=window.history.back() value=back>
397.42.前進(jìn)
398.<INPUT TYPE="button" onclick=window.history.forward() value=forward>
399.43.刷新
400.<INPUT TYPE="button" onclick=document.location.reload() value=reload>
401.44.轉(zhuǎn)向指定網(wǎng)頁
402.document.location="http://ww"或者document.location.assign("http://guoguo.com")
403.45.在網(wǎng)頁上顯示實時時間
404.<SCRIPT LANGUAGE="JavaScript">
405.var clock_id;
406.window.onload=function()
407.{
408.clock_id=setInterval("document.form1.txtclock.value=(new Date);",1000)
409.}
410.</SCRIPT>//
411.46.可以下載文件
412.document.location.href="目標(biāo)文件"http://
413.47.連接數(shù)據(jù)庫
414.import java.sql.*;
415.String myDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
416.Class.forName(myDBDriver);
417.Connection conn=DriverManager.getConnection("jdbc:odbc:firm","username","password");
418.Statement stmt=conn.createStatement();
419.ResultSet rs=stmt.executeQuery(sql);
420.rs.getString("column1");//
421.48.可以直接在頁面“div”內(nèi)寫下所需內(nèi)容
422.<INPUT TYPE="button" onclick="a1.innerHTML='<font color=red>*</font>'">
423.<div id=a1></div>//
424.49.可以改變頁面上的連接的格式,使其為雙線
425.<style>
426.A:link {text-decoration: none; color:#0000FF; font-family: 宋體}
427.A:visited {text-decoration: none; color: #0000FF; font-family: 宋體}
428.A:hover {text-decoration: underline overline; color: FF0000}
429.</style>
430.<style>
431.A:link {text-decoration: none; color:#0000FF; font-family: 宋體}
432.A:visited {text-decoration: none; color: #0000FF; font-family: 宋體}
433.A:hover {text-decoration: underline overline line-through; color: FF0000}
434.TH{FONT-SIZE: 14px}
435.TD{FONT-SIZE: 14px}
436.body {SCROLLBAR-FACE-COLOR:#A9D46D; SCROLLBAR-HIGHLIGHT-COLOR: #e7e7e7;SCROLLBAR-SHADOW-COLOR:#e7e7e7;
437.SCROLLBAR-3DLIGHT-COLOR:#000000; LINE-HEIGHT: 15pt; SCROLLBAR-ARROW-COLOR: #ffffff;
438.SCROLLBAR-TRACK-COLOR:#e7e7e7;}
439.INPUT{BORDER-TOP-WIDTH: 1px; PADDING-RIGHT: 1px; PADDING-LEFT: 1px; BORDER-LEFT-WIDTH: 1px; FONT-SIZE:
440.14px; BORDER-LEFT-COLOR: #cccccc;
441.BORDER-BOTTOM-WIDTH: 1px; BORDER-BOTTOM-COLOR: #cccccc; PADDING-BOTTOM: 1px; BORDER-TOP-COLOR: #cccccc;
442.PADDING-TOP: 1px; HEIGHT: 18px; BORDER-RIGHT-WIDTH: 1px; BORDER-RIGHT-COLOR: #cccccc}
443.DIV,form ,OPTION,P,TD,BR{FONT-FAMILY: 宋體; FONT-SIZE: 14px}
444.textarea, select {border-width: 1;border-color: #000000; background-color: #efefef; font-family: 宋體;
445. font-style: bold;}
446..text { font-family: "宋體"; color: #003300; border:#006600 solid; border-width: 1px 1px
447.1px 1px}
448.</style>完整的css
449.50.新建frame
450.<a
451.href="javascript:newframe('http://www.163.net/help/a_little/index.html','http://www.163.net/help/a_little
452./a_13.html')"><img alt=幫助 border=0 src="http://bjpic.163.net/images/mail/button-help.gif"></a>
453.51.向文件中寫內(nèi)容
454.<%@ page import="java.io.*" %>
455.<%
456.String str = "print me";
457.//always give the path from root. This way it almost always works.
458.String nameOfTextFile = "/usr/anil/imp.txt";
459.try
460.{
461. PrintWriter pw = new PrintWriter(new FileOutputStream(nameOfTextFile));
462. pw.println(str);
463. //clean up
464. pw.close();
465.}
466.catch(IOException e)
467.{
468. out.println(e.getMessage());
469.}
470.%>
471.52.先讀文件再寫文件
472.<%@ page language = "java" %>
473.<%@ page contentType ="text/html; charSet=gb2312" %>
474.<%@ page import ="java.util.*" %>
475.<%@ page import ="java.lang.*" %>
476.<%@ page import="javax.servlet.*" %>
477.<%@ page import="javax.servlet.jsp.*" %>
478.<%@ page import="javax.servlet.http.*" %>
479.<%@ page import="java.io.*" %>
480.eryrytry
481.<%
482.int count=0;
483.FileInputStream fi =new FileInputStream ("count.txt");
484.ObjectInputStream si= new ObjectInputStream (fi);
485.count =si.readInt();
486.count++;
487.out.print(count);
488.si.close();
489.FileOutputStream fo =new FileOutputStream ("count.txt");
490.ObjectOutputStream so= new ObjectOutputStream (fo);
491.so.writeInt(count);
492.so.close();
493.%>
494.53.直線型輸入框
495.<INPUT name=Password size=10 type=password style="border-left-width: 0; border-right-width: 0;
496.border-top-width: 0; border-bottom-style: solid; border-bottom-width: 1; background-color: #9CEB9C">
497.54.可以將背景改為按鈕性狀,通過改變css改變屬性
498.<td width="65" align="center" bgcolor="#E0E0E0" onmouseover=this.className='mouseoverbt';
499.onmouseout=this.className='mouseout';><a href="tm.asp?classid=76"><font
500.color="#000000">錄音筆</font></a></td>
501.<style>
502..mouseoverbt
503.{
504.background-image: url( [圖] );
505.background-repeat: no-repeat;
506.}
507..mouseout
508.{
509.background-color: #E0E0E0;
510.}
511.</style>
512.55.同時按下CTRL和Q鍵
513.document.onkeydown=function()
514.{
515.if(event.ctrlKey&&event.keyCode==81)
516.{alert(1)}
517.}//
518.56.以下是一個完整的顯示hint的代碼,其思想是當(dāng)鼠標(biāo)停留是將div中的內(nèi)容顯示在鼠標(biāo)出,當(dāng)鼠標(biāo)移出后在將該div隱
519.藏掉
520.
521.<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
522.<HTML>
523.<style>
524.#hint{
525.width:198px;
526.border:1px solid #000000;
527.background:#99ff33;
528.position:absolute;
529.z-index:9;
530.padding:6px;
531.line-height:17px;
532.text-align:left;
533.top: 1520px;
534.}
535.</style>
536.<SCRIPT LANGUAGE="JavaScript">
537.<!--
538.function showme()
539.{
540.var oSon=window.document.getElementById("hint");
541.if (oSon==null) return;
542.with (oSon)
543.{
544. innerText=guoguo.value;
545. style.display="block";
546. style.pixelLeft=window.event.clientX+window.document.body.scrollLeft+6;
547. style.pixelTop=window.event.clientY+window.document.body.scrollTop+9;
548.}
549.}
550.function hidme()
551.{
552.var oSon=window.document.getElementById("hint");
553.if (oSon==null) return;
554.oSon.style.display="none";
555.}
556.//-->
557.</SCRIPT>
558.<BODY>
559.<text id=guoguo value=ga>
560.<a href=# onmouseover=showme()onmouseout=hidme() onmousemove=showme() son=hint>dfdfd</a>
561.<div id=hint style="display:none"></div>
562.</BODY>
563.</HTML>
564.---------------------------------------------------------------------------------------------------------
565.------------
566.57.彈出窗口
567.方法一:<body onload="openwen()"> 瀏覽器讀頁面時彈出窗口;
568.方法二:<body onunload="openwen()"> 瀏覽器離開頁面時彈出窗口;
569.方法三:用一個連接調(diào)用:<a href="#" onclick="openwin()">打開一個窗口</a>
570.注意:使用的"#"是虛連接。
571.方法四:用一個按鈕調(diào)用:<input type="button" onclick="openwin()" value="打開窗口"> 何時裝載script
572.58.動態(tài)改變字體的大小
573.function doZoom(size)
574.{
575. document.getElementById('zoom').style.fontSize=size+'px'
576.}
577.function aa()
578.{
579. var newWin=window.open(url);
580. newWin.document.form1.text1.value=value1;
581.}改變彈出窗口上域的屬性
582.opener.document.form2.text2.value=value2;改變父窗口的域的值
583.59.判斷是何種瀏覽器
584.var name = navigator.appName;
585.if (name == "Microsoft Internet Explorer")
586.alert("IE");
587.else if (name == "Netscape")
588.alert("NS");//
589.60.vbsscript確定框
590.<script language="VBScript">
591.<!--
592.MsgBox "確定刪除嗎?", 4
593.//-->
594.</script>//
595.61.復(fù)制內(nèi)容到剪切板
596.function JM_cc(bb)
597.{
598. var ob=eval("document.form1."+bb);
599. ob.select();
600. js=ob.createTextRange();
601. js.execCommand("Copy");
602.}//
603.62.java中建立數(shù)據(jù)庫連接取數(shù)據(jù)
604.public void init()
605.{
606.String url="jdbc:odbc:javadata";
607.try
608.{
609. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
610. Connection con=DriverManager.getConnection(url,"sa","");//mssql database user SA and password
611. DatabaseMetaData dma=con.getMetaData();
612. System.out.println("Connect to"+dma.getURL());
613. System.out.println(";Driver"+dma.getDriverName());
614. System.out.println(";Version"+dma.getDriverVersion());
615. System.out.println("");
616. Statement stmt=con.createStatement();
617. ResultSet rs=stmt.executeQuery("select * from company.dbo.TB_NAME wherenumber=1");//Sql
618. rs.next();
619. String dispresult=rs.getString("name");
620. System.out.println(dispresult);// Instead,you can display it in Paint() or use AWT etc.
621. rs.close();
622. stmt.close();
623. con.close();
624.}
625.catch(SQLException ex)
626.{
627. System.out.println("!!!SQL Exception !!!");
628. while(ex!=null)
629. {
630. System.out.println("SQLState:"+ex.getSQLState());
631. System.out.println("Message:"+ex.getMessage());
632. System.out.println("Vendor:"+ex.getErrorCode());
633. ex=ex.getNextException();
634. System.out.println("");
635. }
636.}
637.catch(java.lang.Exception ex)
638.{
639. ex.printStackTrace();
640.}
641.}//
642.63.最小化窗口
643.window.blur()//
644.64.文檔的路徑
645.document.URL//
646.65.定時執(zhí)行某段程序
647.setTimeout("change_color()",600);
648.66.設(shè)置為主頁
649.function makeHome(){
650. netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesWrite");
651. navigator.preference("browser.startup.homepage", location.href);
652.}//
653.67.設(shè)置為收藏
654.function addFav(){
655. if(ie)
656. window.external.AddFavorite(location.href,'WWW.OGRISH.COM : GROTESQUE MOVIES AND PICTURES');
657. if(ns)
658. alert("Thanks for the bookmark!\n\nNetscape users clickOK then press CTRL-D");
659.}//
660.68.判斷cookie是否可用
661.navigator.cookieEnabled;//
662.69.顯示有模式的有頁面的彈出窗口
663.function setbgcolor_onclick()
664.{
665.var color = showModalDialog("/mailpage/compose/colorsel.html",0,"help=0");
666.if (color != null)
667.{
668. document.compose.bgcolor.value= color;
669.}
670.}//
671.70.截取小數(shù)點(diǎn)后兩位
672.var a=3454545.4454545;
673.alert(a.toFixed(2));//
674.71.禁止選擇頁面上的文字來拷貝
675.<script>
676.function noEffect() {
677. with (event) {
678. returnValue = false;
679. cancelBubble = true;
680. }
681. return;
682.}
683.</script>
684.<body onselectstart="noEffect()" oncontextmenu="noEffect()">//
685.72.屏蔽右鍵菜單
686.oncontextmenu="event.returnValue = false"http://
687.73.事件禁止起泡
688.event.cancelBubble = true//
689.74.禁止在輸入框打開輸入法
690.<input style="ime-mode: disabled">//
691.75.屏蔽漢字和空格
692.<input name="txt"><input type="submit" onClick="alert(!/[^ -}]|\s/.test(txt.value))">//
693.76.用javascript判斷文件是否存在
694.function Exists(filespec)
695.{
696.if (filespec)
697.{
698. var fso;
699. fso = new ActiveXObject("Scripting.FileSystemObject");
700. alert(fso.FileExists(filespec));
701.}
702.}
703.選擇圖片 <input type=file name=f1><p>
704.<input type="submit" onClick="Exists(f1.value)">//
705.77.獲得當(dāng)前的文本框選中的文字
706.<input onmouseup="alert(document.selection.createRange().text)" value=123>//
707.78.跳轉(zhuǎn)至目標(biāo)頁面,同時不可返回
708.<a href="javascript:location.replace('http://www.sohu.com/')">sohu.com</a>//
709.79.獲得當(dāng)前的行是表格的第幾行
710.<script>
711.function getrow(obj)
712.{
713. if(event.srcElement.tagName=="TD"){
714. curRow=event.srcElement.parentElement;
715. alert("這是第"+(curRow.rowIndex+1)+"行");
716. }
717.}
718.</script>
719.<table border="1" width="100%" onclick=getrow(this)>
720. <tr>
721. <td width="20%"> </td>
722. <td width="20%"> </td>
723. <td width="20%"> </td>
724. <td width="20%"> </td>
725. <td width="20%"> </td>
726. </tr>
727. <tr>
728. <td width="20%"> </td>
729. <td width="20%"> </td>
730. <td width="20%"> </td>
731. <td width="20%"> </td>
732. <td width="20%"> </td>
733. </tr>
734.</table>//
735.80.刪除表格某行,xx表示某行,下標(biāo)從0開始計算
736.document.all.myTable.deleteRow(xx)//
737.81.動態(tài)的向表格中添加行
738.<table id="t1" border="1">
739.</table>
740.<script language="JavaScript">
741.function add()
742.{
743. t1.insertRow().insertCell().innerHTML = '<input name="test'+t1.rows.length+'">';
744.}//
745.82.event.x,event.clientX,event.offsetX區(qū)別:
746.x:設(shè)置或者是得到鼠標(biāo)相對于目標(biāo)事件的父元素的外邊界在x坐標(biāo)上的位置。 clientX:相對于客戶區(qū)域的x坐標(biāo)位置,不
747.包括滾動條,就是正文區(qū)域。 offsetx:設(shè)置或者是得到鼠標(biāo)相對于目標(biāo)事件的父元素的內(nèi)邊界在x坐標(biāo)上的位置。
748.screenX:相對于用戶屏幕。
749.83.顯示是鼠標(biāo)按鈕的哪個
750.<body onMouseDown="alert(event.button)">點(diǎn)Mouse看看//
751.84.打開C盤
752.<form action="file:///c|/"><input type="submit" value="c:\ drive"></form>//
753.85.當(dāng)前屏幕的分辨率
754.screen.width、screen.height//
755.86.設(shè)置表格中的內(nèi)容
756.tbl.rows[0].cells[1].innerText=document.form.text1.value;//
757.87.本地快捷鍵
758.<p><a href="file:///::{208D2C60-3AEA-1069-A2D7-08002B30309D}" target="_blank">網(wǎng)上鄰居</a></p>
759.<p><a href="file:///::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\d:\web" target="_blank">我的電腦</a></p>
760.<p><a href="file:///::{450D8FBA-AD25-11D0-98A8-0800361B1103}" target="_blank">我的文檔</a></p>
761.<p><a href="file:///::{645FF040-5081-101B-9F08-00AA002F954E}" target="_blank">回收站</a></p>
762.<p><a href="file:///::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{21EC2020-3AEA-1069-A2DD-08002B30309D}"
763.target="_blank">控制面板</a></p>
764.<p><a href="file:///::{7007ACC7-3202-11D1-AAD2-00805FC1270E}">撥號網(wǎng)絡(luò)</a>(Windows 2000)</p>
765.88.IE菜單
766.<button onclick="min.Click()"><font face="webdings">0</font></button>//改變按鈕上的圖片
767.<input type=button onclick="document.execCommand('CreateLink','true','true')"> //創(chuàng)建新連接
768.<input type=button onclick="document.execCommand('print','true','true')"> //打印
769.<input type=button onclick="document.execCommand('saveas','true','網(wǎng)站制作.htm')">//另存為htm
770.<input type=button onclick="document.execCommand('saveas','true','網(wǎng)站制作.txt')">//另存為txt
771.document.execCommand("SaveAs")//保存為
772.document.execCommand('undo')//撤銷上一次操作
773.89.web對話框
774.<SCRIPT>
775.var contents='<style>body,td{font:menu}img{cursor:hand}</style>';
776.contents+='<title>你要關(guān)閉我嗎</title>';
777.contents+='<body bgcolor=menu>';
778.contents+='<table width=100% height=100% border=0>';
779.contents+='<tr><td align=center>';
780.contents+='你要關(guān)閉我嗎?<br>';
781.contents+='<img src=dark.gif onclick=self.close() alt="...關(guān)閉">';
782.contents+='<img src=jet.gif onclick=self.close() alt="全是關(guān)閉">';
783.contents+='</td></tr></table>';
784.showModalDialog("about:"+contents+"","","dialogHeight:50px;dialogWidth:250px;help:no;status:no")
785.document.write(contents);
786.</SCRIPT>//
787.90.取第x,y的值
788.<button onclick="t1.rows[x].cells[y].innerText='guoguo'"></button>//
789.91.向新打開的網(wǎng)頁上寫內(nèi)容
790.newwin=window.open('about:blank','','top=10');
791.newwin.document.write('');//
792.93.返回
793.javascript:history.go(-2);//
794.94.將頁面上選中的內(nèi)容復(fù)制到剪貼板
795.abcdefg
796.<input type='button'
797.onclick="window.clipboardData.setData('text',document.selection.createRange().text);" value='復(fù)制頁面選中
798.的字符'>//
799.95.將頁面上選中的內(nèi)容復(fù)制到剪貼板
800.<INPUT TYPE="text" NAME="">kjhkjhkhkj<INPUT TYPE="button" onclick="document.execCommand('Copy', 'false',
801.null);">////
802.96.鼠標(biāo)移到下拉框時自動全部打開
803.<select onmouseover="javascript:this.size=this.length" onmouseout="javascript:this.size=1"></select>//
804.97.獲得本機(jī)的文件
805.var fso = new ActiveXObject("Scripting.FileSystemObject");
806.var f1 = fso.GetFile("C:\\bsitcdata\\ejbhome.xml");
807.alert("File last modified: " + f1.DateLastModified); //
808.98.判斷客戶端是否是IE瀏覽器
809.因為 document.all 是 IE 的特有屬性,所以通常用這個方法來判斷客戶端是否是IE瀏覽器,document.all?1:0;
810.99.創(chuàng)建新的下拉框選項
811.new Option(text,value)這樣的函數(shù)//
812.100.在頁面上畫柱狀圖
813.<STYLE>
814.td{font-size:14px}
815.body{font-size:14px}
816.v\:*{behavior:url(#default#VML);} //這里聲明了v作為VML公用變量
817.</STYLE>
818.<SCRIPT LANGUAGE="JavaScript">
819.mathstr=12;
820.document.write ("<v:rect fillcolor='red'
821.style='width:20;color:navy;height:"+5000/(1000/mathstr)+"'><br> %"+mathstr+"<br>4人<v:Extrusion
822.backdepth='15pt' on='true'/></v:rect>")
823.</SCRIPT>
824.<v:rect fillcolor='red' style='width:20;color:navy;height:200'><br>%12<br>4人<v:Extrusion
825.backdepth='15pt' on='true'/></v:rect>
826.<v:rect fillcolor='yellow' style='width:20;color:navy;height:100'><br>%12<br>4人<v:Extrusion
827.backdepth='15pt' on='true'/></v:rect>//
828.101.餅圖
829.<style>
830.v\:* { behavior: url(#default#VML) }
831.o\:* { behavior: url(#default#VML) }
832..shape { behavior: url(#default#VML) }
833.</style>
834.<script language="javascript">
835.function show(pie)
836.{
837.pie.strokecolor=pie.fillcolor;
838.pie.strokeweight=10;
839.div1.innerHTML="<font size=2 color=red> " + pie.id +"</font> <font size=2>" + pie.title +"</font>";
840.}
841.function hide(pie)
842.{
843.pie.strokecolor="white";
844.pie.strokeweight=1;
845.div1.innerHTML="";
846.}
847.</script>
848.</head>
849.<body>
850.<v:group style='width: 5cm; height:5cm' coordorigin='0,0' coordsize='250,250'>
851.<v:shape id='asp技術(shù)' style='width:10;height:10;top:10;left:0' title='得票數(shù):6 比例:40.00%'
852.onmouseover='javascript:show(this);' onmouseout='javascript:hide(this);' strokecolor='white' fillcolor='#ffff33'><v:path v='m 300,200 ae
854.300,200,200,150,0,9437184 xe'/></v:shape>
855.<v:shape id='php' style='width:10;height:10;top:10;left:0' title='得票數(shù):1 比例:6.67%'
856.onmouseover='javascript:show(this);' onmouseout='javascript:hide(this);' strokecolor='white' fillcolor='#ff9933'><v:path v='m 300,200 ae
858.300,200,200,150,9437184,1572864xe'/></v:shape>
859.<v:shape id='jsp' style='width:10;height:10;top:10;left:0' title='得票數(shù):2 比例:13.33%'
860.onmouseover='javascript:show(this);' onmouseout='javascript:hide(this);' strokecolor='white' fillcolor='#3399ff'><v:path v='m 300,200 ae
862.300,200,200,150,11010048,3145728 xe'/></v:shape>
863.<v:shape id='c#寫的.netWEB程序' style='width:10;height:10;top:10;left:0' title='得票數(shù):3 比例:20.00%'
864.onmouseover='javascript:show(this);' onmouseout='javascript:hide(this);' strokecolor='white' fillcolor='#99ff33'><v:path v='m 300,200 ae
866.300,200,200,150,14155776,4718592 xe'/></v:shape>
867.<v:shape id='vb.net寫的.netWEB程序' style='width:10;height:10;top:10;left:0' title='得票數(shù):2 比例:13.33%'
868.onmouseover='javascript:show(this);' onmouseout='javascript:hide(this);' strokecolor='white' fillcolor='#ff6600'><v:path v='m 300,200 ae
870.300,200,200,150,18874368,3145728 xe'/></v:shape>
871.<v:shape id='xml技術(shù)' style='width:10;height:10;top:10;left:0' title='得票數(shù):1 比例:6.67%'
872.onmouseover='javascript:show(this);' onmouseout='javascript:hide(this);' strokecolor='white' fillcolor='#ff99ff'><v:path v='m 300,200 ae
874.300,200,200,150,22020096,1572864 xe'/></v:shape>
875.</v:group>
876.<v:group style='width: 6cm; height:6cm' coordorigin='0,0' coordsize='250,250'>
877.<v:rect style='height:10;width:15;top:0;left:10' fillcolor='#ffff33'/>
878.<v:rect style='height:28;width:100;top:0;left:30' stroked='false'><v:textbox
879.style='fontsize:2'>asp技術(shù)</v:textbox/></v:rect>
880.<v:rect style='height:10;width:15;top:30;left:10' fillcolor='#ff9933'/>
881.<v:rect style='height:28;width:100;top:30;left:30' stroked='false'><v:textbox
882.style='fontsize:2'>php</v:textbox/></v:rect>
883.<v:rect style='height:10;width:15;top:60;left:10' fillcolor='#3399ff'/>
884.<v:rect style='height:28;width:100;top:60;left:30' stroked='false'><v:textbox
885.style='fontsize:2'>jsp</v:textbox/></v:rect>
886.<v:rect style='height:10;width:15;top:90;left:10' fillcolor='#99ff33'/>
887.<v:rect style='height:28;width:100;top:90;left:30' stroked='false'><v:textbox
888.style='fontsize:2'>c#寫的.netWEB程序</v:textbox/></v:rect>
889.<v:rect style='height:10;width:15;top:120;left:10' fillcolor='#ff6600'/>
890.<v:rect style='height:28;width:100;top:120;left:30' stroked='false'><v:textbox style='fontsize:2'>vb.net
891.寫的.netWEB程序</v:textbox/></v:rect>
892.<v:rect style='height:10;width:15;top:150;left:10' fillcolor='#ff99ff'/>
893.<v:rect style='height:28;width:100;top:150;left:30' stroked='false'><v:textbox style='fontsize:2'>xml技術(shù)
894.</v:textbox/></v:rect>
895.</v:group>
896.<div style="position: absolute; left: 10; top: 10; width: 760; height:16">
897.<table border="1" cellpadding="2" cellspacing="2" cellpadding="0" cellspacing="0"
898.style="border-collapse: collapse" bordercolor="#CCCCCC" width="100%" ID="Table1">
899. <tr>
900. <td width="100%" id=div1> </td>
901. </tr>
902.</table>
903.</div>//
904.102.是一個特殊的容器,想裝個網(wǎng)頁都行
905.<button><iframe src="http://www.google.com/"></iframe></button>//button
906.103.外部的html代碼
907.event.srcElement.outerHTML//
908.104.標(biāo)識當(dāng)前的IE事件的觸發(fā)器
909.event.srcElement和event.keyCode//
910.105.事件類型
911.event.type//
912.106.動態(tài)改變類型
913.<style>
914..Overnone { border-width:0;background-color:darkblue;cursor:default;color:gold;width:115}
915..Outnone {border-width:0;background-color:white;cursor:default;width:115}
916.</style>
917.<input class=Outnone onmouseover=this.className='Overnone' >//
918.107.頁面翻轉(zhuǎn)
919.<html dir=rtl></html>//
920.108.滾屏
921.parent.scroll(x,y);//
922.<body onload="s=0" onDblClick="s=setInterval('scrollBy(0, 1)',10)" onClick="clearInterval(s)">//
923.109.改變狀態(tài)欄
924.self.status ="";//
925.110.改變窗口大小
926.window.resizeTo(200,300);//
927.111.改變鼠標(biāo)樣式
928.style
929.BODY{CURSOR: url('mouse.ani');
930.SCROLLBAR-BASE-COLOR: #506AA8;
931.SCROLLBAR-ARROW-COLOR:#14213F;
932.}//
933.112.背景透明
934.<input type="button" value="Button" style="background-color: transparent; border: 0;">//
935.113.鼠標(biāo)為等待形狀
936.<input type=button onclick="this.style.cursor='wait'">//
937.114.調(diào)用父窗口的函數(shù)
938.opener.fucntion1();//
939.115.body的內(nèi)部html代碼
940.<input type="button" onclick="alert(code.document.body.innerHTML)" value="查看">//
941.116.框架中調(diào)用父窗口的函數(shù)
942.<INPUT TYPE='button' onclick='parent.test();' value='調(diào)用parent窗口的函數(shù)'>//
943.117.交換節(jié)點(diǎn)
944.<table width=200 height=200 border>
945.<tr><td id=c1>CELL_1</td></tr>
946.<tr><td id=c2>CELL_2</td></tr>
947.</table>
948.<br>
949.<input type="button" value="swap row" onclick="c1.swapNode(c2)">//
950.118.刪除節(jié)點(diǎn)
951.<table width=200 height=200 border>
952.<tr id=trall><td id=c1>CELL_1</td></tr>
953.<tr><td id=c2>CELL_2</td></tr>
954.</table>
955.<br>
956.<input type="button" value="swap row" onclick="trall.removeNode(c2)">//
957.119.添加節(jié)點(diǎn)
958.addNode()//
959.120.獲得事件的父與子標(biāo)簽
960.event.srcElement.children[0]和event.srcElement.parentElement //
961.121.集中為按鈕改變顏色
962.<style>
963.button{benc:expression(this.onfocus = function(){this.style.backgroundColor='#E5F0FF';})}
964.</style>
965.<button>New</button>//
966.122.判斷是左鍵還是右鍵被按下
967.<body onmousedown=if(event.button==1)alert("左鍵");if(event.button==2)alert("右鍵")>//
968.123.獲得操作系統(tǒng)的名稱和瀏覽器的名稱
969.document.write(navigator.userAgent)//
970.124.alt/ctrl/shift鍵按下
971.event.altKey //按下alt鍵
972.event.ctrlKey //按下ctrl鍵
973.event.shiftKey //按下shift鍵
974.125.將當(dāng)前位置定位為C盤。
975.{window.location="c:"}//
976.126.返回輸入框的類型
977.<script>
978.alert(event.srcElement.type);//
979.</script>
980.
981.
982.
983.
1.127.模擬控件的單擊事件
2.<INPUT TYPE="hidden" name="guoguo" onclick="haha()">
3.<SCRIPT LANGUAGE="JavaScript">
4.<!--
5.function haha()
6.{
7.alert();
8.}
9.guoguo.click();
10.//-->
11.</SCRIPT>//
12.128.取出記錄集的列名
13.java.sql.ResultSet rset = com.bsitc.util.DBAssist.getIT().executeQuery(queryStatement, conn);
14.java.sql.ResultSetMetaData metaData = rset.getMetaData();
15.int count = metaData.getColumnCount();
16.String name = metaData.getColumnName(i);
17.String value = rset.getString(i);//
18.129.格式化數(shù)字
19.function format_number(str,digit)
20.{
21.if(isNaN(str))
22.{
23. alert("您傳入的值不是數(shù)字!");
24. return 0;
25.}
26.else if(Math.round(digit)!=digit)
27.{
28. alert("您輸入的小數(shù)位數(shù)不是整數(shù)!");
29. return 0;
30.}
31.else
32. return Math.round(parseFloat(str)*Math.pow(10,digit))/Math.pow(10,digit);
33.}
34.130.回車按鈕轉(zhuǎn)化為tab按鈕
35.if(event.keyCode==13) event.keyCode=9; //將
36.131.滾動條滾動
37.<button onclick="text1.scrollTop=text1.scrollHeight">Scroll</button><br>
38.<textarea id="text1" cols=50 rows=10>
39.1
40.1
41.1
42.1
43.1
44.1
45.1
46.1
47.1
48.1
49.1
50.1
51.1
52.1
53.1
54.</textarea>//
55.
56.132.判斷是什么對象
57.if(typeof(unknown)=="function")return true;
58.if(typeof(unknown)!="object")return false;//
59.133.取消文本框自動完成功能
60.<input type="text" autocomplete="off"> //
61.134.讓下拉框自動下拉
62.<select onmouseover="javascript:this.size=this.length" onmouseout="javascript:this.size=1">
63.<option value="">1</option>
64.<option value="">2</option>
65.<option value="">3</option>
66.</select> //
67.135.讀取XML文件
68.var childrenobj=myselect//document.all.myselect;
69. var oXMLDoc = new ActiveXObject('MSXML');
70. oXMLDoc.url = "mymsg.xml";
71. var oRoot=oXMLDoc.root;
72. if(oRoot.children != null)
73.{
74. for(var i=0;i<oRoot.children.item(0).children.length;++i)
75. {
76. oItem = oRoot.children.item(0).children.item(i);
77. oOption = new Option(oItem.text,oItem.value);
78. childrenobj.add(oOption);
79. }
80. }
81.//mymsg.xml文件
82.<?xml version="1.0" encoding="gb2312" ?>
83.<childrenlist>
84.<aa>
85.<child value='3301'>杭州地區(qū)</child>
86.<child value='3303'>溫州地區(qū)</child>
87.</aa>
88.<aa>
89.<child value='3310'>臺州地區(qū)</child>
90.<child value='3311'>麗水地區(qū)</child>
91.</aa>
92.</childrenlist>//
93.136.點(diǎn)擊圖片,圖片停止
94.<a href="javascript:"><img src="http://www.51js.com/images/51js/red_forum.gif" border="0"></a>//
95.137.顯示本地計算機(jī)信息
96.var WshNetwork = new ActiveXObject("WScript.Network");
97.alert("Domain = " + WshNetwork.UserDomain);
98.alert("Computer Name = " + WshNetwork.ComputerName);
99.alert("User Name = " + WshNetwork.UserName);//
100.138.比較時間
101. tDate = new Date(2004,01,08,14,35); //年,月,日,時,分
102. dDate = new Date();
103. tDate<dDate?alert("早于"):alert("晚于");//
104.139.彈出鼠標(biāo)所在處的鏈結(jié)地址
105. <body onmouseover="if (event.srcElement.tagName=='A')alert(event.srcElement.href)"><a
106.>dddd</a><input>//
107.140.注意不能通過與 undefined 做比較來測試一個變量是否存在,雖然可以檢查它的類型是否為“undefined”。在以
108.下的代碼范例中,假設(shè)程序員想測試是否已經(jīng)聲明變量 x :
109.// 這種方法不起作用
110.if (x == undefined)
111. // 作某些操作
112.// 這個方法同樣不起作用- 必須檢查
113.// 字符串 "undefined"
114.if (typeof(x) == undefined)
115. // 作某些操作
116.// 這個方法有效
117.if (typeof(x) == "undefined")
118. // 作某些操作
119.141.創(chuàng)建具有某些屬性的對象
120.var myObject = new Object();
121.myObject.name = "James";
122.myObject.age = "22";
123.myObject.phone = "555 1234";//
124.142.枚舉(循環(huán))對象的所有屬性
125.for (var a in myObject)
126.{
127. // 顯示 "The property 'name' isJames",等等。
128. window.alert("The property '"+ a + "' is " + myObject[a]);
129.}//
130.143.判斷一個數(shù)字是否是整數(shù)
131.var a=23.2;
132.alert(a%1==1)//
133.144.新建日期型變量
134.var a = new Date(2000, 1, 1);
135.alert(a.toLocaleDateString());
136.145.給類定義新的方法
137.function trim_1()
138.{
139. return this.replace(/(^\s*)|(\s*$)/g, "");
140.}
141.String.prototype.trim=trim_1;
142.alert('cindy'.trim());
143.146.定義一個將日期類型轉(zhuǎn)化為字符串的方法
144.function guoguo_date()
145.{
146.var tmp1,tmp2;
147.tmp1 =this.getMonth()+1+"";
148.if(tmp1.length<2)
149. tmp1="0"+tmp1;
150.tmp2 =this.getDate()+"";
151.if(tmp2.length<2)
152. tmp2="0"+tmp2;
153.return this.getYear()+"-"+tmp1+"-"+tmp2;
154.}
155.Date.prototype.toLiteString=guoguo_date;
156.alert(new Date().toLiteString())
157.147. pasta 是有四個參數(shù)的構(gòu)造器,定義對象。
158.function pasta(grain, width, shape, hasEgg)
159.{
160. // 是用什么糧食做的?
161. this.grain = grain;
162. // 多寬?(數(shù)值)
163. this.width = width;
164. // 橫截面形狀?(字符串)
165. this.shape = shape;
166. // 是否加蛋黃?(boolean)
167. this.hasEgg = hasEgg;
168. //定義方法
169. this.toString=aa;
170.}
171.function aa()
172.{
173.;
174.}
175.//定義了對象構(gòu)造器后,用 new 運(yùn)算符創(chuàng)建對象實例。
176.var spaghetti = new pasta("wheat", 0.2, "circle", true);
177.var linguine = new pasta("wheat", 0.3, "oval", true);
178.//補(bǔ)充定義屬性,spaghetti和linguine都將自動獲得新的屬性
179.pasta.prototype.foodgroup ="carbohydrates";
180.148.打印出錯誤原因
181.try
182.{
183.x = y // 產(chǎn)生錯誤。
184.}
185.catch(e)
186.{
187. document.write(e.description) //打印 "'y' is undefined".
188.}//
189.149.生成Excel文件并保存
190.var ExcelSheet;
191.ExcelApp = new ActiveXObject("Excel.Application");
192.ExcelSheet = new ActiveXObject("Excel.Sheet");
193.//本代碼啟動創(chuàng)建對象的應(yīng)用程序(在這種情況下,Microsoft Excel 工作表)。一旦對象被創(chuàng)建,就可以用定義的對
194.象變量在代碼中引用它。 在下面的例子中,通過對象變量 ExcelSheet 訪問新對象的屬性和方法和其他 Excel 對象,
195.包括 Application 對象和 ActiveSheet.Cells 集合。
196.// 使 Excel 通過 Application 對象可見。
197.ExcelSheet.Application.Visible = true;
198.// 將一些文本放置到表格的第一格中。
199.ExcelSheet.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";
200.// 保存表格。
201.ExcelSheet.SaveAs("C:\\TEST.XLS");
202.// 用 Application 對象用 Quit 方法關(guān)閉 Excel。
203.ExcelSheet.Application.Quit();//
204.150.根據(jù)標(biāo)簽獲得一組對象
205.var coll = document.all.tags("DIV");
206.if (coll!=null)
207.{
208.for (i=0; i<coll.length; i++)
209....
210.}//
211.151.實現(xiàn)打印預(yù)覽及打印
212.<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=wb name=wb width=0></OBJECT>
213.<input type=button value=打印預(yù)覽 onclick="wb.execwb(7,1)">
214.<input type=button onClick=document.all.wb.ExecWB(6,1) value="打印">//
215.152.不通過form,直接通過名字引用對象
216.<INPUT TYPE="text" NAME="gg" value=aaaaa>
217.<SCRIPT LANGUAGE="JavaScript">
218.<!--
219.alert(document.all.gg.value)
220.//-->
221.</SCRIPT>//
222.153.使鼠標(biāo)滾輪失效
223.function document.onmousewheel()
224.{
225.return false;
226.}//
227.154.創(chuàng)建彈出窗口
228.<SCRIPT LANGUAGE="JScript">
229. var oPopup = window.createPopup();
230. var oPopupBody = oPopup.document.body;
231. oPopupBody.innerHTML = "Displaysome <B>HTML</B> here.";
232. oPopup.show(100, 100, 200, 50, document.body);
233.</SCRIPT>//
234.155.取得鼠標(biāo)所在處的對象
235.var obj = document.elementFromPoint(event.x,event.y);//
236.156.獲得左邊的對象
237.<INPUT TYPE="text" NAME="gg"><INPUT TYPE="text" NAME="bb"
238.onclick="this.previousSibling.value='guoguo'">//
239.157.定位鼠標(biāo)
240.document.all.hint_layer.style.left =event.x+document.body.scrollLeft+10;
241.document.all.hint_layer.style.top =event.y+document.body.scrollTop+10;//
242.158.向下拉框指定位置添加項目
243.var op = document.createElement("OPTION");
244.document.all.selected_items.children(index).insertAdjacentElement("BeforeBegin",op);
245.op.text = document.all.all_items .text;
246.op.value = document.all.all_items .value;//
247.159.判斷一個窗口是否已經(jīng)打開,如果已經(jīng)打開,則關(guān)閉之
248.var a;
249.if(a)
250.a.close();
251.else
252.a=window.open('','','');//
253.160.動態(tài)創(chuàng)建一個標(biāo)簽
254.newElem = document.createElement("DIV");
255.newElem.id = "hint_layer";
256.document.body.appendChild(newElem);
257.document.all.hint_layer.innerText="guoguo";//
258.161.標(biāo)題欄
259.document.title//
260.162.背景圖片
261.<body style="BACKGROUND-ATTACHMENT: fixed" background="img/bgfix.gif" ></body>//背景圖片不動
262.<STYLE TYPE="text/css">
263.<!--
264.BODY {background-image:img/bgchild.jpg;
265.background-position: center;
266.background-repeat: no-repeat;
267.background-attachment: fixed;}
268.-->
269.</STYLE>//背景圖片居中
270.163.設(shè)置透明效果
271.document.form.xxx.filters.alpha.opacity=0~100//
272.164.定義方法
273.var dragapproved=false;
274.document.onmouseup=new Function("dragapproved = false");//
275.165.將數(shù)字轉(zhuǎn)化為人民幣大寫形式
276.function convertCurrency(currencyDigits) {
277.// Constants:
278.var MAXIMUM_NUMBER = 99999999999.99;
279.// Predefine the radix characters and currency symbols for output:
280.var CN_ZERO = "零";
281.var CN_ONE = "壹";
282.var CN_TWO = "貳";
283.var CN_THREE = "叁";
284.var CN_FOUR = "肆";
285.var CN_FIVE = "伍";
286.var CN_SIX = "陸";
287.var CN_SEVEN = "柒";
288.var CN_EIGHT = "捌";
289.var CN_NINE = "玖";
290.var CN_TEN = "拾";
291.var CN_HUNDRED = "佰";
292.var CN_THOUSAND = "仟";
293.var CN_TEN_THOUSAND = "萬";
294.var CN_HUNDRED_MILLION = "億";
295.var CN_SYMBOL = "人民幣";
296.var CN_DOLLAR = "元";
297.var CN_TEN_CENT = "角";
298.var CN_CENT = "分";
299.var CN_INTEGER = "整";
300.// Variables:
301.var integral; // Represent integralpart of digit number.
302.var decimal; // Represent decimal part of digit number.
303.var outputCharacters; // The output result.
304.var parts;
305.var digits, radices, bigRadices, decimals;
306.var zeroCount;
307.var i, p, d;
308.var quotient, modulus;
309.// Validate input string:
310.currencyDigits = currencyDigits.toString();
311.if (currencyDigits == "") {
312. alert("Empty input!");
313. return "";
314.}
315.if (currencyDigits.match(/[^,.\d]/) != null) {
316. alert("Invalid characters in the input string!");
317. return "";
318.}
319.if ((currencyDigits).match(/^((\d{1,3}(,\d{3})*(.((\d{3},)*\d{1,3}))?)|(\d+(.\d+)?))$/) == null) {
320. alert("Illegal format of digit number!");
321. return "";
322.}
323.// Normalize the format of input digits:
324.currencyDigits = currencyDigits.replace(/,/g, ""); // Remove comma delimiters.
325.currencyDigits = currencyDigits.replace(/^0+/, ""); //Trim zeros at the beginning.
326.// Assert the number is not greater than the maximum number.
327.if (Number(currencyDigits) > MAXIMUM_NUMBER) {
328. alert("Too large a number to convert!");
329. return "";
330.}
331.// http://www.knowsky.com/ Process the coversion from currency digits to characters:
332.// Separate integral and decimal parts before processing coversion:
333.parts = currencyDigits.split(".");
334.if (parts.length > 1) {
335. integral = parts[0];
336. decimal = parts[1];
337. // Cut down redundant decimal digits that are after the second.
338. decimal = decimal.substr(0, 2);
339.}
340.else {
341. integral = parts[0];
342. decimal = "";
343.}
344.// Prepare the characters corresponding to the digits:
345.digits = new Array(CN_ZERO, CN_ONE, CN_TWO, CN_THREE, CN_FOUR, CN_FIVE, CN_SIX, CN_SEVEN, CN_EIGHT,
346.CN_NINE);
347.radices = new Array("", CN_TEN, CN_HUNDRED, CN_THOUSAND);
348.bigRadices = new Array("", CN_TEN_THOUSAND, CN_HUNDRED_MILLION);
349.decimals = new Array(CN_TEN_CENT, CN_CENT);
350.// Start processing:
351.outputCharacters = "";
352.// Process integral part if it is larger than 0:
353.if (Number(integral) > 0) {
354. zeroCount = 0;
355. for (i = 0; i < integral.length; i++){
356. p = integral.length - i - 1;
357. d = integral.substr(i, 1);
358. quotient = p / 4;
359. modulus = p % 4;
360. if (d == "0") {
361. zeroCount++;
362. }
363. else {
364. if (zeroCount > 0)
365. {
366. outputCharacters += digits[0];
367. }
368. zeroCount = 0;
369. outputCharacters += digits[Number(d)] + radices[modulus];
370. }
371. if (modulus == 0 && zeroCount < 4) {
372. outputCharacters += bigRadices[quotient];
373. }
374. }
375. outputCharacters += CN_DOLLAR;
376.}
377.// Process decimal part if there is:
378.if (decimal != "") {
379. for (i = 0; i < decimal.length; i++) {
380. d = decimal.substr(i, 1);
381. if (d != "0") {
382. outputCharacters += digits[Number(d)] + decimals ;
383. }
384. }
385.}
386.// Confirm and return the final output string:
387.if (outputCharacters == "") {
388. outputCharacters = CN_ZERO + CN_DOLLAR;
389.}
390.if (decimal == "") {
391. outputCharacters += CN_INTEGER;
392.}
393.outputCharacters = CN_SYMBOL + outputCharacters;
394.return outputCharacters;
395.}//
396.166.xml數(shù)據(jù)島綁定表格
397.<html>
398.<body>
399.<xml id="abc" src="test.xml"></xml>
400.<table border='1' datasrc='#abc'>
401.<thead>
402.<td>接收人</td>
403.<td>發(fā)送人</td>
404.<td>主題</td>
405.<td>內(nèi)容</td>
406.</thead>
407.<tfoot>
408.<tr><th>表格的結(jié)束</th></tr>
409.</tfoot>
410.<tr>
411.<td><div datafld="to"></div></td>
412.<td><div datafld="from"></div></td>
413.<td><div datafld="subject"></div></td>
414.<td><div datafld="content"></div></td>
415.</tr>
416.</table>
417.</body>
418.</html>
419.//cd_catalog.xml
420.<?xml version="1.0" encoding="ISO-8859-1" ?>
421.<!-- Edited with XML Spy v4.2
422. -->
423.<CATALOG>
424.<CD>
425. <TITLE>Empire Burlesque</TITLE>
426. <ARTIST>Bob Dylan</ARTIST>
427. <COUNTRY>USA</COUNTRY>
428. <COMPANY>Columbia</COMPANY>
429. <PRICE>10.90</PRICE>
430. <YEAR>1985</YEAR>
431. </CD>
432.<CD>
433. <TITLE>Hide your heart</TITLE>
434. <ARTIST>Bonnie Tyler</ARTIST>
435. <COUNTRY>UK</COUNTRY>
436. <COMPANY>CBS Records</COMPANY>
437. <PRICE>9.90</PRICE>
438. <YEAR>1988</YEAR>
439. </CD>
440.<CD>
441. <TITLE>Greatest Hits</TITLE>
442. <ARTIST>Dolly Parton</ARTIST>
443. <COUNTRY>USA</COUNTRY>
444. <COMPANY>RCA</COMPANY>
445. <PRICE>9.90</PRICE>
446. <YEAR>1982</YEAR>
447. </CD>
448.<CD>
449. <TITLE>Still got the blues</TITLE>
450. <ARTIST>Gary Moore</ARTIST>
451. <COUNTRY>UK</COUNTRY>
452. <COMPANY>Virgin records</COMPANY>
453. <PRICE>10.20</PRICE>
454. <YEAR>1990</YEAR>
455. </CD>
456.</CATALOG>
457.//
458.167.以下組合可以正確顯示漢字
459.================================
460.xml保存編碼 xml頁面指定編碼
461.ANSI gbk/GBK、gb2312
462.Unicode unicode/Unicode
463.UTF-8 UTF-8
464.================================
465.168.XML操作
466.<xml id="xmldata" src="/data/books.xml">
467.<div id="guoguo"></div>
468.<script>
469.var x=xmldata.recordset //取得數(shù)據(jù)島中的記錄集
470.if(x.absoluteposition < x.recordcount) //如果當(dāng)前的絕對位置在最后一條記錄之前
471.{
472.x.movenext(); //向后移動
473.x.moveprevious(); //向前移動
474.x.absoluteposition=1; //移動到第一條記錄
475.x.absoluteposition=x.recordcount;//移動到最后一條記錄,注意記錄集x.absoluteposition是從1到記錄集記錄的個
476.數(shù)的
477.guoguo.innerText=xmldso.recordset("field_name"); //從中取出某條記錄
478.}
479.</script>
480.169.動態(tài)修改CSS的另一種方式
481.this.runtimeStyle.cssText ="color:#990000;border:1px solid#cccccc";//
482.170.正則表達(dá)式
483.匹配中文字符的正則表達(dá)式: [\u4e00-\u9fa5]
484.匹配雙字節(jié)字符(包括漢字在內(nèi)):[^\x00-\xff]
485.應(yīng)用:計算字符串的長度(一個雙字節(jié)字符長度計2,ASCII字符計1)
486.String.prototype.len=function(){return this.replace([^\x00-\xff]/g,"aa").length;}
487.匹配空行的正則表達(dá)式:\n[\s| ]*\r
488.匹配HTML標(biāo)記的正則表達(dá)式:/<(.*)>.*<\/\1>|<(.*) \/>/
489.匹配首尾空格的正則表達(dá)式:(^\s*)|(\s*$)
490.應(yīng)用:javascript中沒有像vbscript那樣的trim函數(shù),我們就可以利用這個表達(dá)式來實現(xiàn),如下:
491.String.prototype.trim = function()
492.{
493. return this.replace(/(^\s*)|(\s*$)/g, "");
494.}
495.////////利用正則表達(dá)式分解和轉(zhuǎn)換IP地址:
496.下面是利用正則表達(dá)式匹配IP地址,并將IP地址轉(zhuǎn)換成對應(yīng)數(shù)值的Javascript程序:
497.function IP2V(ip)
498.{
499.re=/(\d+)\.(\d+)\.(\d+)\.(\d+)/g //匹配IP地址的正則表達(dá)式
500.if(re.test(ip))
501.{
502.return RegExp.$1*Math.pow(255,3))+RegExp.$2*Math.pow(255,2))+RegExp.$3*255+RegExp.$4*1
503.}
504.else
505.{
506.throw new Error("Not a valid IP address!")
507.}
508.}
509.不過上面的程序如果不用正則表達(dá)式,而直接用split函數(shù)來分解可能更簡單,程序如下:
510.var ip="10.100.20.168"
511.ip=ip.split(".")
512.alert("IP值是:"+(ip[0]*255*255*255+ip[1]*255*255+ip[2]*255+ip[3]*1))
513.匹配Email地址的正則表達(dá)式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
514.匹配網(wǎng)址URL的正則表達(dá)式:http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
515.//////////利用正則表達(dá)式去除字串中重復(fù)的字符的算法程序:
516.var s="abacabefgeeii"
517.var s1=s.replace(/(.).*\1/g,"$1")
518.var re=new RegExp("["+s1+"]","g")
519.var s2=s.replace(re,"")
520.alert(s1+s2) //結(jié)果為:abcefgi
521.思路是使用后向引用取出包括重復(fù)的字符,再以重復(fù)的字符建立第二個表達(dá)式,取到不重復(fù)的字符,兩者串連。這個方
522.法對于字符順序有要求的字符串可能不適用。
523.//////////得用正則表達(dá)式從URL地址中提取文件名的javascript程序,如下結(jié)果為page1
524.s="http://www.9499.net/page1.htm"
525.s=s.replace(/(.*\/){0,}([^\.]+).*/ig,"$2")
526.alert(s)
527./////////利用正則表達(dá)式限制網(wǎng)頁表單里的文本框輸入內(nèi)容:
528.用正則表達(dá)式限制只能輸入中文:onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')"
529.onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,'')
530.)"
531.用正則表達(dá)式限制只能輸入全角字符: onkeyup="value=value.replace(/[^\uFF00-\uFFFF]/g,'')"
532.onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\uFF00-\uFFFF]/g,'')
533.)"
534.用正則表達(dá)式限制只能輸入數(shù)字:onkeyup="value=value.replace(/[^\d]/g,'')
535."onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
536.用正則表達(dá)式限制只能輸入數(shù)字和英文:onkeyup="value=value.replace(/[\W]/g,'')
537."onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
538.171.設(shè)置和使用cookie
539.<HTML>
540.<BODY>
541.設(shè)置與讀取 cookies...<BR>
542.寫入cookie的值<input type=text name=gg>
543.<INPUT TYPE = BUTTON Value = "設(shè)置cookie" onClick = "Set()">
544.<INPUT TYPE = BUTTON Value = "讀取cookie" onClick = "Get()"><BR>
545.<INPUT TYPE = TEXT NAME = Textbox>
546.</BODY>
547.<SCRIPT LANGUAGE="JavaScript">
548.function Set()
549.{
550.var Then = new Date()
551.Then.setTime(Then.getTime() + 60*1000 ) //60秒
552.document.cookie ="Cookie1="+gg.value+";expires="+ Then.toGMTString()
553.}
554.function Get()
555.{
556.var cookieString = new String(document.cookie)
557.var cookieHeader = "Cookie1="
558.var beginPosition = cookieString.indexOf(cookieHeader)
559.if (beginPosition != -1)
560.{
561. document.all.Textbox.value = cookieString.substring(beginPosition + cookieHeader.length)
562.}
563.else
564. document.all.Textbox.value ="Cookie 未找到!"
565.}
566.</SCRIPT>
567.</HTML>//
568.172.取月的最后一天
569.function getLastDay(year,month)
570.{
571.//取年
572.var new_year = year;
573.//取到下一個月的第一天,注意這里傳入的month是從1~12
574.var new_month = month++;
575.//如果當(dāng)前是12月,則轉(zhuǎn)至下一年
576.if(month>12)
577.{
578. new_month -=12;
579. new_year++;
580.}
581.var new_date = new Date(new_year,new_month,1);
582.return (new Date(new_date.getTime()-1000*60*60*24)).getDate();
583.}//
584.173.判斷當(dāng)前的焦點(diǎn)是組中的哪一個
585.for(var i=0;i<3;i++)
586.if(event.srcElement==bb )
587. break;//
588.174.實現(xiàn)類
589.package com.baosight.view.utils;
590.import javax.servlet.jsp.tagext.TagSupport;
591.import javax.servlet.http.HttpSession;
592.public class Mytag extends TagSupport
593.{
594. public int doStartTag() throws javax.servlet.jsp.JspException
595. {
596. boolean canAccess = false;
597. HttpSession session= pageContext.getSession();
598. if (canAccess)
599. {
600. return EVAL_BODY_INCLUDE;
601. }
602. else
603. {
604. return this.SKIP_BODY;
605. }
606. }
607.}
608.175.在web.xml中添加定義
609. <taglib>
610. <taglib-uri>guoguo</taglib-uri>
611. <taglib-location>/WEB-INF/abc.tld</taglib-location>
612. </taglib>
613.176.標(biāo)簽庫中定義abc.tld
614.<?xml version="1.0" encoding="UTF-8"?>
615.<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
616."http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
617.<taglib>
618.<tlibversion>1.0</tlibversion>
619.<jspversion>1.1</jspversion>
620.<shortname>hr</shortname>
621.<uri>guoguo</uri>
622.<info>Extra 3 Tag Library</info>
623.<tag>
624. <name>mytag</name>
625. <tagclass>com.baosight.view.utils.Mytag</tagclass>
626. <attribute>
627. <name>id2</name>
628. <required>true</required>
629. <rtexprvalue>true</rtexprvalue>
630. </attribute>
631.</tag>
632.</taglib>
633.177.在使用自定義標(biāo)簽的頁面中加入自己定義的標(biāo)簽,
634.<%@ taglib uri="guoguo" prefix="guoguo" %>
635.//自己定義標(biāo)簽
636.178.顯示帶邊框的集
637.<fieldset style="border:1px gray solid;width:100px">
638. <legend>查詢條件</legend>
639.dfdfdf
640.</fieldset>//
641.179.【文件(F)】菜單中的命令的實現(xiàn)
642.1、〖打開〗命令的實現(xiàn)
643.[格式]:document.execCommand("open")
644.[說明]這跟VB等編程設(shè)計中的webbrowser控件中的命令有些相似,大家也可依此琢磨琢磨。
645.[舉例]在<body></body>之間加入:
646.<a href="###" onclick=document.execCommand("open")>打開</a>
647.2、〖使用 記事本 編輯〗命令的實現(xiàn)
648.[格式]:location.replace("view-source:"+location)
649.[說明]打開記事本,在記事本中顯示該網(wǎng)頁的源代碼。
650.[舉例]在<body></body>之間加入:
651.<a href="###" onclick=location.replace("view-source:"+location)>使用 記事本編輯</a>
652.3、〖另存為〗命令的實現(xiàn)
653.[格式]:document.execCommand("saveAs")
654.[說明]將該網(wǎng)頁保存到本地盤的其它目錄!
655.[舉例]在<body></body>之間加入:
656.<a href="###" onclick=document.execCommand("saveAs")>另存為</a>
657.4、〖打印〗命令的實現(xiàn)
658.[格式]:document.execCommand("print")
659.[說明]當(dāng)然,你必須裝了打印機(jī)!
660.[舉例]在<body></body>之間加入:
661.<a href="###" onclick=document.execCommand("print")>打印</a>
662.5、〖關(guān)閉〗命令的實現(xiàn)
663.[格式]:window.close();return false
664.[說明]將關(guān)閉本窗口。
665.[舉例]在<body></body>之間加入:
666.<a href="###" onclick=window.close();return false)>關(guān)閉本窗口</a>
667.180.【編輯(E)】菜單中的命令的實現(xiàn)
668.〖全選〗命令的實現(xiàn)
669.[格式]:document.execCommand("selectAll")
670.[說明]將選種網(wǎng)頁中的全部內(nèi)容!
671.[舉例]在<body></body>之間加入:
672.<a href="###" onclick=document.execCommand("selectAll")>全選</a>
673.181.【查看(V)】菜單中的命令的實現(xiàn)
674.1、〖刷新〗命令的實現(xiàn)
675.[格式]:location.reload() 或 history.go(0)
676.[說明]瀏覽器重新打開本頁。
677.[舉例]在<body></body>之間加入:
678.<a href="###" onclick=location.reload()>刷新</a>
679.或加入:
680.<a href="###" onclick=history.go(0)>刷新</a>
681.2、〖源文件〗命令的實現(xiàn)
682.[格式]:location.replace("view-source:"+location)
683.[說明]查看該網(wǎng)頁的源代碼。
684.[舉例]在<body></body>之間加入:
685.<a href="###" onclick=location.replace("view-source:"+location)>查看源文件</a>
686.3、〖全屏顯示〗命令的實現(xiàn)
687.[格式]:window.open(document.location, "url", "fullscreen")
688.[說明]全屏顯示本頁。
689.[舉例]在<body></body>之間加入:
690.<a href="###" onclick=window.open(document.location,"url","fullscreen")>全屏顯示</a>
691.182.【收藏(A)】菜單中的命令的實現(xiàn)
692.1、〖添加到收藏夾〗命令的實現(xiàn)
693.[格式]:window.external.AddFavorite('url', '“網(wǎng)站名”)
694.[說明]將本頁添加到收藏夾。
695.[舉例]在<body></body>之間加入:
696.<a href="javascript:window.external.AddFavorite('http://oh.jilinfarm.com','胡明新的個人主頁')">添加到收
697.藏夾</a>
698.2、〖整理收藏夾〗命令的實現(xiàn)
699.[格式]:window.external.showBrowserUI("OrganizeFavorites",null)
700.[說明]打開整理收藏夾對話框。
701.[舉例]在<body></body>之間加入:
702.<a href="###" onclick=window.external.showBrowserUI("OrganizeFavorites",null)>整理收藏夾</a>
703.183.【工具(T)】菜單中的命令的實現(xiàn)
704.〖internet選項〗命令的實現(xiàn)
705.[格式]:window.external.showBrowserUI("PrivacySettings",null)
706.[說明]打開internet選項對話框。
707.[舉例]在<body></body>之間加入:
708.<a href="###" onclick=window.external.showBrowserUI("PrivacySettings",null)>internet選項</a>
709.184.【工具欄】中的命令的實現(xiàn)
710.1、〖前進(jìn)〗命令的實現(xiàn)
711.[格式]history.go(1) 或 history.forward()
712.[說明]瀏覽器打開后一個頁面。
713.[舉例]在<body></body>之間加入:
714.<a href="###" onclick=history.go(1)>前進(jìn)</a>
715.或加入:
716.<a href="###" onclick=history.forward()>前進(jìn)</a>
717.2、〖后退〗命令的實現(xiàn)
718.[格式]:history.go(-1) 或 history.back()
719.[說明]瀏覽器返回上一個已瀏覽的頁面。
720.[舉例]在<body></body>之間加入:
721.<a href="###" onclick=history.go(-1)>后退</a>
722.或加入:
723.<a href="###" onclick=history.back()>后退</a>
724.3、〖刷新〗命令的實現(xiàn)
725.[格式]:document.reload() 或 history.go(0)
726.[說明]瀏覽器重新打開本頁。
727.[舉例]在<body></body>之間加入:
728.<a href="###" onclick=location.reload()>刷新</a>
729.或加入:
730.<a href="###" onclick=history.go(0)>刷新</a>
731.185.其它命令的實現(xiàn)
732.〖定時關(guān)閉本窗口〗命令的實現(xiàn)
733.[格式]:settimeout(window.close(),關(guān)閉的時間)
734.[說明]將關(guān)閉本窗口。
735.[舉例]在<body></body>之間加入:
736.<a href="###" onclick=settimeout(window.close(),3000)>3秒關(guān)閉本窗口</a>
737.【附】為了方便讀者,下面將列出所有實例代碼,你可以把它們放到一個html文件中,然后預(yù)覽效果。
738.<a href="###" onclick=document.execCommand("open")>打開</a><br>
739.<a href="###" onclick=location.replace("view-source:"+location)>使用 記事本編輯</a><br>
740.<a href="###" onclick=document.execCommand("saveAs")>另存為</a><br>
741.<a href="###" onclick=document.execCommand("print")>打印</a><br>
742.<a href="###" onclick=window.close();return false)>關(guān)閉本窗口</a><br>
743.<a href="###" onclick=document.execCommand("selectAll")>全選</a><br>
744.<a href="###" onclick=location.reload()>刷新</a> <a href="###" onclick=history.go(0)>刷新</a><br>
745.<a href="###" onclick=location.replace("view-source:"+location)>查看源文件</a><br>
746.<a href="###" onclick=window.open(document.location,"url","fullscreen")>全屏顯示</a><br>
747.<a href="javascript:window.external.AddFavorite('http://homepage.yesky.com', '天極網(wǎng)頁陶吧')">添加到收藏
748.夾</a><br>
749.<a href="###" onclick=window.external.showBrowserUI("OrganizeFavorites",null)>整理收藏夾</a><br>
750.<a href="###" onclick=window.external.showBrowserUI("PrivacySettings",null)>internet選項</a><br>
751.<a href="###" onclick=history.go(1)>前進(jìn)1</a> <a href="###" onclick=history.forward()>前進(jìn)2</a><br>
752.<a href="###" onclick=history.go(-1)>后退1</a> <a href="###" onclick=history.back()>后退2</a><br>
753.<a href="###" onclick=settimeout(window.close(),3000)>3秒關(guān)閉本窗口</a><br>
754.186.給DHTML中的標(biāo)簽添加一個新的屬性,可以隨意加
755.<BODY onload="alert(a1.epass)">
756.<input type=text name="a1" epass="zhongguo">
757.</BODY>//
758.187.xmlhttp技術(shù)
759.<BODY> 此方法是通過XMLHTTP對象從服務(wù)器獲取XML文檔,示例如下。
760.<input type=button value="加載XML文檔" onclick="getData('data.xml')" >
761.<script language="JavaScript" >
762.function getDatal(url){
763.var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");//創(chuàng)建XMLHTTPRequest對象
764.xmlhttp.open("GET",url,false,"","");//使用HTTP GET初始化HTTP請求
765.xmlhttp.send("");//發(fā)送HTTP請求并獲取HTTP響應(yīng)
766.return xmlhttp.responseXML;//獲取XML文檔
767.}
768.</script >
769.</BODY>//
770.188.服務(wù)器端通過request.getReader()獲得傳入的字符串
771.189.在java中使用正則表達(dá)式
772.java.util.regex.Pattern p =
773.java.util.regex.Pattern.compile("\\d+|.\\d+|\\d+.\\d*|(E|\\d+E|.\\d+E|\\d+.\\d*E)((\\+|-)\\d|\\d)\\d*");
774.java.util.regex.Matcher m = p.matcher("12.E+3");
775.boolean result = m.matches();//
776.190.給下拉框分組
777.<SELECT>
778.<OPTGROUP LABEL="堿性金屬">
779.<OPTION>鋰 (Li)</OPTION>
780.<OPTION>納 (Na)</OPTION>
781.<OPTION>鉀 (K)</OPTION>
782.</OPTGROUP>
783.<OPTGROUP LABEL="鹵素">
784.<OPTION>氟 (F)</OPTION>
785.<OPTION>氯 (Cl)</OPTION>
786.<OPTION>溴 (Br)</OPTION>
787.</OPTGROUP>
788.</SELECT>//
789.191.加注音
790.<RUBY>
791.基準(zhǔn)文本
792.<RT>注音文本
793.</RUBY>//
794.192.加刪除線
795.<S>此文本將帶刪除線顯示。</S>//
796.193.取frame中的event事件
797.document.frames("workspace").event.keyCode//
798.194.是彈出方法的定義
799.String.prototype.trim=function()
800.{
801.return this.replace(/(^\s*)|(\s*$)/g, "");
802.}
803.alert(" ".trim)//
804.195.防止網(wǎng)頁被包含
805.if (window != window.top)
806.top.location.href = location.href;//
807.196.讓網(wǎng)頁一直在frame里面
808.if(window==window.top)
809.{
810.document.body.innerHTML="<center><h1>請通過正常方式訪問本頁面!</h1></center>";
811.//window.close();
812.}//
813.197.加為首頁
814.<SCRIPT>
815.function fnSet(){
816.oHomePage.setHomePage(location.href);
817.event.returnValue = false;
818.}
819.</SCRIPT>
820.<IE:HOMEPAGE ID="oHomePage" style="behavior:url(#default#homepage)"/>//
821.198.xml數(shù)據(jù)島操作
822.<HTML>
823. <HEAD><Title>HTML中的數(shù)據(jù)島中的記錄集</Title></HEAD>
824. <body bkcolor=#EEEEEE text=bluebgcolor="#00FFFF">
825. <Table align=center width="100%"><TR><TD align="center">
826. <h5><b><font size="4" color="#FF0000">HTML中的XML數(shù)據(jù)島記錄編輯與添加 </font></b></h5>
827. </TD></TR></Table>
828. <HR>
829. 酒店名稱:<input type=text datasrc=#theXMLisland DataFLD=NAME size="76"><BR>
830. 地址:<input type=text datasrc=#theXMLisland DataFLD=Address size="76"><BR>
831. 主頁:<input type=text datasrc=#theXMLisland DataFLD=HomePage size="76"><BR>
832. 電子郵件:<input type=text datasrc=#theXMLisland DataFLD=E-Mail size="76"><BR>
833. 電話:<input type=text datasrc=#theXMLisland DataFLD=TelePhone size="76"><BR>
834. 級別:<input type=text datasrc=#theXMLisland DataFLD=Grade size="76"><HR>
835. <input id="first" TYPE=button value="<< 第一條記錄" onclick="theXMLisland.recordset.moveFirst()">
836. <input id="prev" TYPE=button value="<上一條記錄" onclick="theXMLisland.recordset.movePrevious()">
837. <input id="next" TYPE=button value="下一條記錄>" onclick="theXMLisland.recordset.moveNext()">
838. <input id="last" TYPE=button value="最后一條記錄>>" onclick="theXMLisland.recordset.moveLast()">
839. <input id="Add" TYPE=button value="添加新記錄" onclick="theXMLisland.recordset.addNew()">
840. <XML ID="theXMLisland">
841. <HotelList>
842. <Hotel>
843. <Name>四海大酒店</Name>
844. <Address>?;曷?號</Address>
845. <HomePage> www.sihaohotel.com.cn </HomePage>
846. <E-Mail> master@sihaohotel.com.cn </E-Mail>
847. <TelePhone>(0989)8888888</TelePhone>
848. <Grade>五星級</Grade>
849. </Hotel>
850. <Hotel>
851. <Name>五湖賓館</Name>
852. <Address>東平路99號</Address>
853. <HomePage> www.wuhu.com.cn </HomePage>
854. <E-Mail> web@wuhu.com.cn </E-Mail>
855. <TelePhone>(0979)1111666</TelePhone>
856. <Grade>四星級</Grade>
857. </Hotel>
858. <Hotel>
859. <Name>“大沙漠”賓館</Name>
860. <Address>留香路168號</Address>
861. <HomePage> www.dashamohotel.com.cn </HomePage>
862. <E-Mail> master@dashamohotel.com.cn </E-Mail>
863. <TelePhone>(0989)87878788</TelePhone>
864. <Grade>五星級</Grade>
865. </Hotel>
866. <Hotel>
867. <Name>“畫眉鳥”大酒店</Name>
868. <Address>血海飄香路2號</Address>
869. <HomePage> www.throstlehotel.com.cn </HomePage>
870. <E-Mail> chuliuxiang@throstlehotel.com.cn </E-Mail>
871. <TelePhone>(099)9886666</TelePhone>
872. <Grade>五星級</Grade>
873. </Hotel>
874. </HotelList>
875. </XML>
876. </body>
877. </HTML> //xml數(shù)據(jù)島中添加記錄
878.-------------------------------
879. The following list is a sample of the properties and methods that you use to access nodes in an XML
880.document.
881.Property/ Method Description
882.XMLDocument Returns a reference to the XML Document Object Model (DOM) exposed by the object.
883.documentElement Returns the document root of the XML document.
884.childNodes Returns a node list containing the children of a node (if any).
885.item Accesses individual nodes within the list through an index. Index values are zero-based, so
886.item(0) returns the first child node.
887.text Returns the text contentof the node.
888.The following code shows an HTMLpage containing an XML data island. The data island is containedwithin
889.the <XML> element.
890.<HTML>
891. <HEAD>
892. <TITLE>HTML with XML Data Island</TITLE>
893. </HEAD>
894. <BODY>
895. <P>Within this document is an XML data island.</P>
896. <XML ID="resortXML">
897. <resorts>
898. <resort code='1'>Adventure Works</resort>
899. <resort>Alpine Ski House</resort>
900. </resorts>
901. </XML>
902. </BODY>
903.</HTML>
904.For an example, you can cut and paste this sample line of code:
905.resortXML.XMLDocument.documentElement.childNodes.item(1).text//讀取頁面上的XML數(shù)據(jù)島中的數(shù)據(jù)
906.resortXML.documentElement.childNodes.item(0).getAttribute("code")//讀取頁面上的XML數(shù)據(jù)島中的數(shù)據(jù)
907.resortXML.documentElement.childNodes[0].getAttribute("code")//讀取頁面上的XML數(shù)據(jù)島中的數(shù)據(jù)
908.
909.199.模式窗口
910.父窗口
911.var url="aaa.jsp";
912.var
913.data=showModalDialog(url,null,"dialogHeight:400px;dialogHeight:600px;center:yes;help:No;status:no;resizab
914.le:Yes;edge:sunken");
915.if(data)
916.alert(data.value);
917.子窗口
918.var data=new Object();
919.data.value1="china";
920.window.returnValue=data;
921.window.close();
922.200.動態(tài)設(shè)置事件,帶參數(shù)
923.<INPUT TYPE="text" NAME="a1">
924.<SCRIPT LANGUAGE="JavaScript">
925.<!--
926.function hah(para)
927.{
928.alert(para)
929.}
930.a1.onclick=function()
931.{
932.hah('canshu ')
933.}
934.//a1.attachEvent("onclick",function(){hah('參數(shù)')});
935.//-->
936.</SCRIPT>//
937.201.將url轉(zhuǎn)化為16進(jìn)制形式
938.var ret = '';
939.for(var i=0; i < str.length; i++)
940.{
941. var ch = str.charAt(i);
942. var code = str.charCodeAt(i);
943. if(code < 128 && ch != '[' && ch!= '\'' && ch != '=')
944. {
945. ret += ch;
946. }
947. else
948. {
949. ret += "[" + code.toString(16) +"]";
950. }
951.}
952.return ret;//
953.202.打開新的窗口并將新打開的窗口設(shè)置為活動窗口
954.var newWin=window.open("xxxx");
955.newWin.focus();//
956.203.容錯腳本
957.JS中遇到腳本錯誤時不做任何操作:window.onerror = doNothing;
958.指定錯誤句柄的語法為:window.onerror = handleError
959.function handleError(message, URI,line)
960.{// 提示用戶,該頁可能不能正確回應(yīng)
961.return true; // 這將終止默認(rèn)信息
962.}//在頁面出錯時進(jìn)行操作
963.204.JS中的窗口重定向:
964.window.navigate("http://www.sina.com.cn");//
965.205.防止鏈接文字折行
966.document.body.noWrap=true;//
967.206.判斷字符是否匹配.
968.string.match(regExpression)//
969.207.
970.href="javascript:document.Form.Name.value='test';void(0);"http://不能用onClick="javacript:document.Form.Name.v
971.alue='test';return false;"
972.當(dāng)使用inline方式添加事件處理腳本事,有一個被包裝成匿名函數(shù)的過程,也就是說
973.onClick="javacript:document.Form.Name.value='test';return false;"被包裝成了:
974.functoin anonymous()
975.{
976. document.Form.Name.value='test';return false;
977.}
978.做為A的成員函數(shù)onclick。
979.而href="javascript:document.Form.Name.value='test';void(0);"相當(dāng)于執(zhí)行全局語句,這時如果使用return語句會
980.報告在函數(shù)外使用return語句的錯誤。
981.208.進(jìn)行頁面放大
982.<P onmouseover="this.style.zoom='200%'" onmouseout="this.style.zoom='normal'">
983.sdsdsdsdsdsdsdsds
984.</p>//
985.209.放置在頁面的最右邊
986.<input type="text" value='bu2' style="float:right">//
987.210.通過style來控制隔行顯示不同顏色
988.<style>
989.tr{
990.bgcolor:expression(this.bgColor=((this.rowIndex)%2==0 )? 'white' : 'yellow');
991.}
992.</style>
993.<table id="oTable" width="100" border="1" style="border-collapse:collapse;">
994.<tr><td> </td></tr>
995.<tr><td> </td></tr>
996.<tr><td> </td></tr>
997.<tr><td> </td></tr>
998.<tr><td> </td></tr>
999.</table>//
1000.211.全屏最大化
1001.newwindow=window.open("","","scrollbars")
1002.if (document.all)
1003.{
1004.newwindow.moveTo(0,0)
1005.newwindow.resizeTo(screen.width,screen.height)
1006.}//
1007.212.根據(jù)名字解析xml中的節(jié)點(diǎn)值
1008.var XMLDoc=new ActiveXObject("MSXML");
1009.XMLDoc.url="d:/abc.xml";
1010.aRoot=XMLDoc.root;
1011.a1.innerText=aRoot.children.item("name").text;//
1012.213.在頁面上解析xml的值
1013.http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/5996c682-3472-4b03-9fb0-1e08
1014.fcccdf35.asp
1015.//
1016.214.看一個字符串里面有多少個回車符,返回值是一個數(shù)組
1017.var s=value.match(/\n/g);if(s)if(s.length==9){alert('10行了');return false;}//
1018.215.獲得asc碼
1019.var s='aa';
1020.alert(s.charCodeAt(1))//
1021.216.文字居右對齊
1022.<input type="text" value="123" style="text-align:right">//
1023.217.判斷一個方法是否存在
1024.function pageCallback(response){
1025.alert(response);
1026.}
1027.if(pageCallback)
1028.alert(1)//
1029.218.判斷一個變量是否定義
1030.if(typeof(a)=="undefined")
1031.{
1032.alert()
1033.}//
1034.219.javascript執(zhí)行本機(jī)的可執(zhí)行程序,需設(shè)置為可信或者降低IE安全級別
1035.<script>
1036.function exec (command) {
1037. window.oldOnError = window.onerror;
1038. window._command = command;
1039. window.onerror = function (err) {
1040. if (err.indexOf('utomation') != -1) {
1041. alert('命令已經(jīng)被用戶禁止!');
1042. return true;
1043. }
1044. else return false;
1045. };
1046. var wsh = new ActiveXObject('WScript.Shell');
1047. if (wsh)
1048. wsh.Run(command);
1049. window.onerror = window.oldOnError;
1050. }
1051.</script>
1052.調(diào)用方式
1053.<a href="javascript:" onclick="exec('D:/test.bat')">測試</a>//
1054.220.彈出新頁面,關(guān)閉舊頁面,不彈出提示框
1055.var w=screen.availWidth-10;
1056. var h=screen.availHeight-10;
1057. var swin=window.open("/mc/mc/message_management.jsp",
1058."BGSMbest","scrollbars=yes,status,location=0,menubar=0,toolbar=0,resizable=no,top=0,left=0,height="+h+",w
1059.idth="+w);
1060. window.opener=null;
1061. window.close();//
1062.221.能輸入的下拉框
1063.<span>
1064.<input name="Department1" id="Department1" style="border-right:0;width:130" autocomplete="off">
1065.<span style="width:150;overflow:hidden">
1066.<select style="width:150;margin-left:-130" onChange="Department1.value=value">
1067.<option value=""></option>
1068.<option value="asdfasfadf">asdfasfadf</option>
1069.<option value="546546">546546</option></select> //
1070.222.在方法中定義全局變量
1071.function globalVar (script) {
1072. eval(script);//all navigators
1073. //window.execScript(script); //forie only
1074.}
1075.globalVar('window.haha ="../system";');
1076.alert(haha);//在方法中定義全局變量,其中的haha就是全局變量了
1077.223.顯示一個對象的全部的屬性和屬性的值
1078.var a=new Object();
1079.a.name='a1';
1080.a.***='mail'
1081.for(var p in a)
1082.{
1083.alert(p+"="+a
)
1084.}//
1085.224.16進(jìn)制轉(zhuǎn)換成10進(jìn)制
1086.var n = parseInt("2AE",16);//這里將16進(jìn)制的 2AE 轉(zhuǎn)成 10 進(jìn)制數(shù),得到 n 的值是 686
1087.225.復(fù)制粘貼
1088.<BODY>
1089.<input type="file" name='a1'><inputtype="button" value='復(fù)制粘貼' onclick="haha()"><div id="aa"></div>
1090.<SCRIPT LANGUAGE="JavaScript">
1091.<!--
1092.function haha()
1093.{
1094.clipboardData.setData("Text",a1.value);
1095.aa.innerText=clipboardData.getData("Text");
1096.}
1097.//-->
1098.</SCRIPT>
1099.</BODY>//
1100.226.獲得對象類型
1101.switch (object.constructor){
1102. case Date:
1103. ...
1104. case Number:
1105. ...
1106. case String:
1107. ...
1108. case MyObject:
1109. ...
1110. default:
1111. ...
1112.}//
1113.227.圖片加載失敗時重新加載圖片
1114.<img src="aa.gif" onerror="this.src='aa.gif'">//
1115.228.
1116.//font_effect.htc
1117.<PUBLIC:ATTACH EVENT="onmouseover" ONEVENT="glowit()" />
1118.<PUBLIC:ATTACH EVENT="onmouseout" ONEVENT="noglow()" />
1119.<SCRIPT LANGUAGE="JScript">
1120.//定義一個保存字體顏色的變量
1121.var color;
1122.function glowit()
1123.{
1124.color=element.style.backgroundColor;
1125.element.style.backgroundColor='white'
1126.}
1127.function noglow()
1128.{
1129. element.style.backgroundColor=color
1130.}
1131.</SCRIPT>
1132.//abc.css
1133.tr{behavior:url(font_effect.htc);}
1134.229.可以通過css和htc改變表格的顏色,僅IE支持
1135.//xxx.html
1136.<link rel="stylesheet" type="text/css" href="abc.css">
1137.<TABLE border='1' id="a1">
1138.<TR style="background-color:red">
1139.<TD>1</TD>
1140.<TD>2</TD>
1141.<TD>3</TD>
1142.</TR>
1143.<TR style="background-color:yellow">
1144.<TD>4</TD>
1145.<TD>5</TD>
1146.<TD>6</TD>
1147.</TR>
1148.</TABLE>//
1149.230.在頁面上畫點(diǎn)
1150.function a(x,y,color)
1151.{
1152.document.write("<img border='0' style='position: absolute; left:"+(x+20)+"; top:
1153."+(y+20)+";background-color:"+color+"' width=1 height=1>")
1154.}//
1155.231.自動關(guān)閉網(wǎng)頁
1156.<script LANGUAGE="javascript">
1157.<!--
1158.setTimeout('window.close();', 10000); //60秒后關(guān)閉
1159.// -->
1160.</script>
1161.<p align="center">本頁10秒后自動關(guān)閉,請注意刷新頁面</p>
該文章在 2012/6/8 9:57:32 編輯過