[建筑]Javascript技巧大集合_第1頁
[建筑]Javascript技巧大集合_第2頁
[建筑]Javascript技巧大集合_第3頁
[建筑]Javascript技巧大集合_第4頁
[建筑]Javascript技巧大集合_第5頁
已閱讀5頁,還剩15頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、.Javascript技巧大集合3171.設置和使用cookie<HTML><BODY>設置與讀取 cookies.<BR>寫入cookie的值<input type=text name=gg><INPUT TYPE = BUTTON Value = "設置cookie" onClick = "Set()"><INPUT TYPE = BUTTON Value = "讀取cookie" onClick = "Get()"><BR>&

2、lt;INPUT TYPE = TEXT NAME = Textbox></BODY><SCRIPT LANGUAGE="JavaScript">function Set()var Then = new Date()Then.setTime(Then.getTime() + 60*1000 ) /60秒document.cookie = "Cookie1="+gg.value+"expires="+ Then.toGMTString()function Get()var cookieString = ne

3、w String(document.cookie)var cookieHeader = "Cookie1="var beginPosition = cookieString.indexOf(cookieHeader)if (beginPosition != -1)document.all.Textbox.value = cookieString.substring(beginPosition + cookieHeader.length)elsedocument.all.Textbox.value = "Cookie 未找到!"</SCRIPT>

4、;</HTML>/172.取月的最后一天function getLastDay(year,month)/取年var new_year = year;/取到下一個月的第一天,注意這里傳入的month是從112var new_month = month+;/如果當前是12月,則轉至下一年if(month>12)new_month -=12;new_year+;var new_date = new Date(new_year,new_month,1);return (new Date(new_date.getTime()-1000*60*60*24).getDate();/173.

5、判斷當前的焦點是組中的哪一個for(var i=0;i<3;i+)if(event.srcElement=bbi)break;/174.實現(xiàn)類package com.baosight.view.utils;import javax.servlet.jsp.tagext.TagSupport;import javax.servlet.http.HttpSession;public class Mytag extends TagSupportpublic int doStartTag() throws javax.servlet.jsp.JspException boolean canAcc

6、ess = false; HttpSession session= pageContext.getSession(); if (canAccess) return EVAL_BODY_INCLUDE; else return this.SKIP_BODY; 175.在web.xml中添加定義<taglib> <taglib-uri>guoguo</taglib-uri> <taglib-location>/WEB-INF/abc.tld</taglib-location></taglib>176.標簽庫中定義abc.tld

7、<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE taglib PUBLIC "-/Sun Microsystems, Inc./DTD JSP Tag Library 1.1/EN""<taglib><tlibversion>1.0</tlibversion><jspversion>1.1</jspversion><shortname>hr</shortname><uri

8、>guoguo</uri><info>Extra 3 Tag Library</info><tag><name>mytag</name><tagclass>com.baosight.view.utils.Mytag</tagclass><attribute> <name>id2</name> <required>true</required> <rtexprvalue>true</rtexprvalue><

9、;/attribute></tag></taglib>177.在使用自定義標簽的頁面中加入自己定義的標簽,<% taglib uri="guoguo" prefix="guoguo" %>/自己定義標簽178.顯示帶邊框的集<fieldset style="border:1px gray solid;width:100px"><legend>查詢條件</legend>dfdfdf</fieldset>/179.【文件(F)】菜單中的命令的實現(xiàn)1、

10、打開命令的實現(xiàn)格式:document.execCommand("open")說明這跟VB等編程設計中的webbrowser控件中的命令有些相似,大家也可依此琢磨琢磨。舉例在<body></body>之間加入:<a href= onclick=document.execCommand("open")>打開</a>2、使用 記事本 編輯命令的實現(xiàn)格式:location.replace("view-source:"+location)說明打開記事本,在記事本中顯示該網(wǎng)頁的源代碼。舉例在<

11、body></body>之間加入:<a href= onclick=location.replace("view-source:"+location)>使用 記事本編輯</a>3、另存為命令的實現(xiàn)格式:document.execCommand("saveAs")說明將該網(wǎng)頁保存到本地盤的其它目錄!舉例在<body></body>之間加入:<a href= onclick=document.execCommand("saveAs")>另存為</a>

12、4、打印命令的實現(xiàn)格式:document.execCommand("print")說明當然,你必須裝了打印機!舉例在<body></body>之間加入:<a href= onclick=document.execCommand("print")>打印</a>5、關閉命令的實現(xiàn)格式:window.close();return false說明將關閉本窗口。舉例在<body></body>之間加入:<a href= onclick=window.close();return fals

13、e)>關閉本窗口</a>180.【編輯(E)】菜單中的命令的實現(xiàn)全選命令的實現(xiàn)格式:document.execCommand("selectAll")說明將選種網(wǎng)頁中的全部內容!舉例在<body></body>之間加入:<a href= onclick=document.execCommand("selectAll")>全選</a>181.【查看(V)】菜單中的命令的實現(xiàn)1、刷新命令的實現(xiàn)格式:location.reload() 或 history.go(0)說明瀏覽器重新打開本頁。舉例在

14、<body></body>之間加入:<a href= onclick=location.reload()>刷新</a>或加入:<a href= onclick=history.go(0)>刷新</a>2、源文件命令的實現(xiàn)格式:location.replace("view-source:"+location)說明查看該網(wǎng)頁的源代碼。舉例在<body></body>之間加入:<a href= onclick=location.replace("view-source:

15、"+location)>查看源文件</a>3、全屏顯示命令的實現(xiàn)格式:window.open(document.location, "url", "fullscreen")說明全屏顯示本頁。舉例在<body></body>之間加入:<a href= onclick=window.open(document.location,"url","fullscreen")>全屏顯示</a>182.【收藏(A)】菜單中的命令的實現(xiàn)1、添加到收藏夾命令的

16、實現(xiàn)格式:window.external.AddFavorite('url', '“網(wǎng)站名”)說明將本頁添加到收藏夾。舉例在<body></body>之間加入:<a href= '胡明新的個人主頁')">添加到收藏夾</a>2、整理收藏夾命令的實現(xiàn)格式:window.external.showBrowserUI("OrganizeFavorites",null)說明打開整理收藏夾對話框。舉例在<body></body>之間加入:<a href= o

17、nclick=window.external.showBrowserUI("OrganizeFavorites",null)>整理收藏夾</a>183.【工具(T)】菜單中的命令的實現(xiàn)internet選項命令的實現(xiàn)格式:window.external.showBrowserUI("PrivacySettings",null)說明打開internet選項對話框。舉例在<body></body>之間加入:<a href= onclick=window.external.showBrowserUI("P

18、rivacySettings",null)>internet選項</a>184.【工具欄】中的命令的實現(xiàn)1、前進命令的實現(xiàn)格式history.go(1) 或 history.forward()說明瀏覽器打開后一個頁面。舉例在<body></body>之間加入:<a href= onclick=history.go(1)>前進</a>或加入:<a href= onclick=history.forward()>前進</a>2、后退命令的實現(xiàn)格式:history.go(-1) 或 history.b

19、ack()說明瀏覽器返回上一個已瀏覽的頁面。舉例在<body></body>之間加入:<a href= onclick=history.go(-1)>后退</a>或加入:<a href= onclick=history.back()>后退</a>3、刷新命令的實現(xiàn)格式:document.reload() 或 history.go(0)說明瀏覽器重新打開本頁。舉例在<body></body>之間加入:<a href= onclick=location.reload()>刷新</a&g

20、t;或加入:<a href= onclick=history.go(0)>刷新</a>185.其它命令的實現(xiàn)定時關閉本窗口命令的實現(xiàn)格式:settimeout(window.close(),關閉的時間)說明將關閉本窗口。舉例在<body></body>之間加入:<a href= onclick=settimeout(window.close(),3000)>3秒關閉本窗口</a>【附】為了方便讀者,下面將列出所有實例代碼,你可以把它們放到一個html文件中,然后預覽效果。<a href= onclick=docume

21、nt.execCommand("open")>打開</a><br><a href= onclick=location.replace("view-source:"+location)>使用 記事本編輯</a><br><a href= onclick=document.execCommand("saveAs")>另存為</a><br><a href= onclick=document.execCommand("print

22、")>打印</a><br><a href= onclick=window.close();return false)>關閉本窗口</a><br><a href= onclick=document.execCommand("selectAll")>全選</a><br> 軟件開發(fā)網(wǎng) <a href= onclick=location.reload()>刷新</a> <a href= onclick=history.go(0)>刷新&

23、lt;/a><br><a href= onclick=location.replace("view-source:"+location)>查看源文件</a><br><a href= onclick=window.open(document.location,"url","fullscreen")>全屏顯示</a><br><a href= '天極網(wǎng)頁陶吧')">添加到收藏夾</a><br>

24、;<a href= onclick=window.external.showBrowserUI("OrganizeFavorites",null)>整理收藏夾</a><br><a href= onclick=window.external.showBrowserUI("PrivacySettings",null)>internet選項</a><br><a href= onclick=history.go(1)>前進1</a><a href= onclic

25、k=history.forward()>前進2</a><br><a href= onclick=history.go(-1)>后退1</a><a href= onclick=history.back()>后退2</a><br> <a href= onclick=settimeout(window.close(),3000)>3秒關閉本窗口</a><br>186.給DHTML中的標簽添加一個新的屬性,可以隨意加<BODY onload="alert(a1.

26、epass)"><input type=text name="a1" epass="zhongguo"></BODY>/187.xmlhttp技術<BODY> 此方法是通過XMLHTTP對象從服務器獲取XML文檔,示例如下。<input type=button value="加載XML文檔" onclick="getData('data.xml')" ><script language="JavaScript"

27、 >function getDatal(url)var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");/創(chuàng)建XMLHTTPRequest對象xmlhttp.open("GET",url,false,"","");/使用HTTP GET初始化HTTP請求xmlhttp.send("");/發(fā)送HTTP請求并獲取HTTP響應return xmlhttp.responseXML;/獲取XML文檔</script ></BODY

28、>/188.服務器端通過request.getReader()獲得傳入的字符串189.在java中使用正則表達式java.util.regex.Pattern p =java.util.regex.Ppile("d+|.d+|d+.d*|(E|d+E|.d+E|d+.d*E)(+|-)d|d)d*");java.util.regex.Matcher m = p.matcher("12.E+3");boolean result = m.matches();/190.給下拉框分組<SELECT><OPTGROUP LABEL=&quo

29、t;堿性金屬"><OPTION>鋰 (Li)</OPTION><OPTION>納 (Na)</OPTION><OPTION>鉀 (K)</OPTION></OPTGROUP><OPTGROUP LABEL="鹵素"><OPTION>氟 (F)</OPTION><OPTION>氯 (Cl)</OPTION><OPTION>溴 (Br)</OPTION></OPTGROUP></

30、SELECT>/191.加注音<RUBY>基準文本<RT>注音文本</RUBY>/192.加刪除線<S>此文本將帶刪除線顯示。</S>/193.取frame中的event事件document.frames("workspace").event.keyCode/194.是彈出方法的定義Stotype.trim=function()return this.replace(/(s*)|(s*$)/g, "");alert(" ".trim)/195.防止網(wǎng)頁

31、被包含if (window != window.top)top.location.href = location.href;/196.讓網(wǎng)頁一直在frame里面if(window=window.top)document.body.innerHTML="<center><h1>請通過正常方式訪問本頁面!</h1></center>"/window.close();/197.加為首頁<SCRIPT>function fnSet()oHomePage.setHomePage(location.href);event.re

32、turnValue = false;</SCRIPT><IE:HOMEPAGE ID="oHomePage" style="behavior:url(#default#homepage)"/>/198.xml數(shù)據(jù)島操作<HTML><HEAD><Title>HTML中的數(shù)據(jù)島中的記錄集</Title></HEAD><body bkcolor=#EEEEEE text=blue bgcolor="#00FFFF"> 軟件開發(fā)網(wǎng) <Tabl

33、e align=center width="100%"><TR><TD align="center"><h5><b><font size="4" color="#FF0000">HTML中的XML數(shù)據(jù)島記錄編輯與添加 </font></b></h5></TD></TR></Table><HR>酒店名稱:<input type=text datasrc= Data

34、FLD=NAME size="76"><BR>地址:<input type=text datasrc= DataFLD=Address size="76"><BR>主頁:<input type=text datasrc= DataFLD=HomePage size="76"><BR>電子郵件:<input type=text datasrc= DataFLD=E-Mail size="76"><BR>電話:<input

35、type=text datasrc= DataFLD=TelePhone size="76"><BR>級別:<input type=text datasrc= DataFLD=Grade size="76"><HR><input id="first" TYPE=button value="<<第一條記錄" onclick="theXMLisland.recordset.moveFirst()"><input id="

36、;prev" TYPE=button value="<上一條記錄" onclick="theXMLisland.recordset.movePrevious()"> <input id="next" TYPE=button value="下一條記錄>" onclick="theXMLisland.recordset.moveNext()"> <input id="last" TYPE=button value="最后一條

37、記錄>>" onclick="theXMLisland.recordset.moveLast()">&nbsp; <input id="Add" TYPE=button value="添加新記錄" onclick="theXMLisland.recordset.addNew()"> <XML ID="theXMLisland"><HotelList><Hotel><Name>四海大酒店</Nam

38、e><Address>?;曷?號</Address><HomePage></HomePage><E-Mail>master</E-Mail><TelePhone>(0989)8888888</TelePhone><Grade>五星級</Grade> 軟件開發(fā)網(wǎng) </Hotel><Hotel><Name>五湖賓館</Name><Address>東平路99號</Address><HomePage&

39、gt;</HomePage><E-Mail>web</E-Mail><TelePhone>(0979)1111666</TelePhone><Grade>四星級</Grade></Hotel><Hotel><Name>“大沙漠”賓館</Name><Address>留香路168號</Address><HomePage></HomePage><E-Mail>master</E-Mail><T

40、elePhone>(0989)87878788</TelePhone><Grade>五星級</Grade></Hotel><Hotel><Name>“畫眉鳥”大酒店</Name><Address>血海飄香路2號</Address><HomePage></HomePage><E-Mail>chuliuxiang</E-Mail><TelePhone>(099)9886666</TelePhone><Grad

41、e>五星級</Grade></Hotel></HotelList></XML></body> </HTML> /xml數(shù)據(jù)島中添加記錄-The following list is a sample of the properties and methods that you use to access nodes in an XMLdocument.Property/ Method DescriptionXMLDocument Returns a reference to the XML Document Objec

42、t Model (DOM) exposed by the object.documentElement Returns the document root of the XML document.childNodes Returns a node list containing the children of a node (if any).item Accesses individual nodes within the list through an index. Index values are zero-based, soitem(0) returns the first child

43、node. 軟件開發(fā)網(wǎng) text Returns the text content of the node.The following code shows an HTML page containing an XML data island. The data island is contained withinthe <XML> element.<HTML><HEAD> <TITLE>HTML with XML Data Island</TITLE></HEAD><BODY> <P>Within

44、 this document is an XML data island.</P> <XML ID="resortXML"> <resorts> <resort code='1'>Adventure Works</resort> <resort>Alpine Ski House</resort> </resorts> </XML></BODY></HTML>For an example, you can cut and past

45、e this sample line of code: resortXML.XMLDocument.documentElement.childNodes.item(1).text/讀取頁面上的XML數(shù)據(jù)島中的數(shù)據(jù)resortXML.documentElement.childNodes.item(0).getAttribute("code")/讀取頁面上的XML數(shù)據(jù)島中的數(shù)據(jù)resortXML.documentElement.childNodes0.getAttribute("code")/讀取頁面上的XML數(shù)據(jù)島中的數(shù)據(jù)199.模式窗口父窗口var ur

46、l="aaa.jsp"vardata=showModalDialog(url,null,"dialogHeight:400px;dialogHeight:600px;center:yes;help:No;status:no;resizable:Yes;edge:sunken");if(data)alert(data.value);子窗口var data=new Object();data.value1="china"window.returnValue=data;window.close();200.動態(tài)設置事件,帶參數(shù)<INP

47、UT TYPE="text" NAME="a1"><SCRIPT LANGUAGE="JavaScript"><!-function hah(para)alert(para)a1.onclick=function()hah('canshu ')/a1.attachEvent("onclick",function()hah('參數(shù)');/-></SCRIPT>/201.將url轉化為16進制形式var ret = ''for(v

48、ar i=0; i < str.length; i+)var ch = str.charAt(i);var code = str.charCodeAt(i);if(code < 128 && ch != '' && ch != ''' && ch != '=') ret += ch;else ret += "" + code.toString(16) + ""return ret;/202.打開新的窗口并將新打開的窗口設置為活動窗口var

49、newWin=window.open("xxxx");newWin.focus();/203.容錯腳本JS中遇到腳本錯誤時不做任何操作:window.onerror = doNothing;指定錯誤句柄的語法為:window.onerror = handleErrorfunction handleError(message, URI, line)/ 提示用戶,該頁可能不能正確回應return true; / 這將終止默認信息/在頁面出錯時進行操作204.JS中的窗口重定向:window.navigate("");/205.防止鏈接文字折行document

50、.body.noWrap=true;/206.判斷字符是否匹配.string.match(regExpression)/207.href="javascript:document.Form.Name.value='test'void(0);"/不能用onClick="javacript:document.Form.Name.value='test'return false;"當使用inline方式添加事件處理腳本事,有一個被包裝成匿名函數(shù)的過程,也就是說onClick="javacript:document.Fo

51、rm.Name.value='test'return false;"被包裝成了:functoin anonymous() document.Form.Name.value='test'return false;做為A的成員函數(shù)onclick。而href="javascript:document.Form.Name.value='test'void(0);"相當于執(zhí)行全局語句,這時如果使用return語句會報告在函數(shù)外使用return語句的錯誤。208.進行頁面放大<P onmouseover="thi

52、s.style.zoom='200%'" onmouseout="this.style.zoom='normal'">sdsdsdsdsdsdsdsds </p>/209.放置在頁面的最右邊<input type="text" value='bu2' style="float:right">/210.通過style來控制隔行顯示不同顏色<style>trbgcolor:expression(this.bgColor=(this.rowI

53、ndex)%2=0 )? 'white' : 'yellow');</style><table id="oTable" width="100" border="1" style="border-collapse:collapse;"><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr><tr>&

54、lt;td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr></table>/211.全屏最大化newwindow=window.open("","","scrollbars")if (document.all)newwindow.moveTo(0,0)newwindow.resizeTo(scr

55、een.width,screen.height)/212.根據(jù)名字解析xml中的節(jié)點值var XMLDoc=new ActiveXObject("MSXML");XMLDoc.url="d:/abc.xml"aRoot=XMLDoc.root;a1.innerText=aRoot.children.item("name").text;/213.在頁面上解析xml的值fcccdf35.asp/214.看一個字符串里面有多少個回車符,返回值是一個數(shù)組var s=value.match(/n/g);if(s)if(s.length=9)al

56、ert('10行了');return false;/215.獲得asc碼var s='aa'alert(s.charCodeAt(1)/216.文字居右對齊<input type="text" value="123" style="text-align:right">/217.判斷一個方法是否存在function pageCallback(response)alert(response);if(pageCallback)alert(1)/218.判斷一個變量是否定義if(typeof(a)=

57、"undefined")alert()/219.javascript執(zhí)行本機的可執(zhí)行程序,需設置為可信或者降低IE安全級別 <script>function exec (command) window.oldOnError = window.onerror; window._command = command; window.onerror = function (err) if (err.indexOf('utomation') != -1) alert('命令已經被用戶禁止!'); return true; else retu

58、rn false; ; var wsh = new ActiveXObject('WScript.Shell'); if (wsh) wsh.Run(command); window.onerror = window.oldOnError;</script>調用方式<a href= onclick="exec('D:/test.bat')">測試</a>/220.彈出新頁面,關閉舊頁面,不彈出提示框var w=screen.availWidth-10; var h=screen.availHeight-10

59、; var swin=window.open("/mc/mc/message_management.jsp","BGSMbest","scrollbars=yes,status,location=0,menubar=0,toolbar=0,resizable=no,top=0,left=0,height="+h+",width="+w); window.opener=null; window.close();/221.能輸入的下拉框<span><input name="Department1" id="Departm

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論