[建筑]Javascript技巧大集合_第1页
[建筑]Javascript技巧大集合_第2页
[建筑]Javascript技巧大集合_第3页
[建筑]Javascript技巧大集合_第4页
[建筑]Javascript技巧大集合_第5页
已阅读5页,还剩15页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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.实现类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)】菜单中的命令的实现1、

10、打开命令的实现格式:document.execCommand("open")说明这跟VB等编程设计中的webbrowser控件中的命令有些相似,大家也可依此琢磨琢磨。举例在<body></body>之间加入:<a href= onclick=document.execCommand("open")>打开</a>2、使用 记事本 编辑命令的实现格式:location.replace("view-source:"+location)说明打开记事本,在记事本中显示该网页的源代码。举例在<

11、body></body>之间加入:<a href= onclick=location.replace("view-source:"+location)>使用 记事本编辑</a>3、另存为命令的实现格式:document.execCommand("saveAs")说明将该网页保存到本地盘的其它目录!举例在<body></body>之间加入:<a href= onclick=document.execCommand("saveAs")>另存为</a>

12、4、打印命令的实现格式:document.execCommand("print")说明当然,你必须装了打印机!举例在<body></body>之间加入:<a href= onclick=document.execCommand("print")>打印</a>5、关闭命令的实现格式:window.close();return false说明将关闭本窗口。举例在<body></body>之间加入:<a href= onclick=window.close();return fals

13、e)>关闭本窗口</a>180.【编辑(E)】菜单中的命令的实现全选命令的实现格式:document.execCommand("selectAll")说明将选种网页中的全部内容!举例在<body></body>之间加入:<a href= onclick=document.execCommand("selectAll")>全选</a>181.【查看(V)】菜单中的命令的实现1、刷新命令的实现格式:location.reload() 或 history.go(0)说明浏览器重新打开本页。举例在

14、<body></body>之间加入:<a href= onclick=location.reload()>刷新</a>或加入:<a href= onclick=history.go(0)>刷新</a>2、源文件命令的实现格式:location.replace("view-source:"+location)说明查看该网页的源代码。举例在<body></body>之间加入:<a href= onclick=location.replace("view-source:

15、"+location)>查看源文件</a>3、全屏显示命令的实现格式:window.open(document.location, "url", "fullscreen")说明全屏显示本页。举例在<body></body>之间加入:<a href= onclick=window.open(document.location,"url","fullscreen")>全屏显示</a>182.【收藏(A)】菜单中的命令的实现1、添加到收藏夹命令的

16、实现格式:window.external.AddFavorite('url', '“网站名”)说明将本页添加到收藏夹。举例在<body></body>之间加入:<a href= '胡明新的个人主页')">添加到收藏夹</a>2、整理收藏夹命令的实现格式:window.external.showBrowserUI("OrganizeFavorites",null)说明打开整理收藏夹对话框。举例在<body></body>之间加入:<a href= o

17、nclick=window.external.showBrowserUI("OrganizeFavorites",null)>整理收藏夹</a>183.【工具(T)】菜单中的命令的实现internet选项命令的实现格式:window.external.showBrowserUI("PrivacySettings",null)说明打开internet选项对话框。举例在<body></body>之间加入:<a href= onclick=window.external.showBrowserUI("P

18、rivacySettings",null)>internet选项</a>184.【工具栏】中的命令的实现1、前进命令的实现格式history.go(1) 或 history.forward()说明浏览器打开后一个页面。举例在<body></body>之间加入:<a href= onclick=history.go(1)>前进</a>或加入:<a href= onclick=history.forward()>前进</a>2、后退命令的实现格式:history.go(-1) 或 history.b

19、ack()说明浏览器返回上一个已浏览的页面。举例在<body></body>之间加入:<a href= onclick=history.go(-1)>后退</a>或加入:<a href= onclick=history.back()>后退</a>3、刷新命令的实现格式:document.reload() 或 history.go(0)说明浏览器重新打开本页。举例在<body></body>之间加入:<a href= onclick=location.reload()>刷新</a&g

20、t;或加入:<a href= onclick=history.go(0)>刷新</a>185.其它命令的实现定时关闭本窗口命令的实现格式: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> 软件开发网 <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= '天极网页陶吧')">添加到收藏夹</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");/创建XMLHTTPRequest对象xmlhttp.open("GET",url,false,"","");/使用HTTP GET初始化HTTP请求xmlhttp.send("");/发送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.防止网页

31、被包含if (window != window.top)top.location.href = location.href;/196.让网页一直在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数据岛操作<HTML><HEAD><Title>HTML中的数据岛中的记录集</Title></HEAD><body bkcolor=#EEEEEE text=blue bgcolor="#00FFFF"> 软件开发网 <Tabl

33、e align=center width="100%"><TR><TD align="center"><h5><b><font size="4" color="#FF0000">HTML中的XML数据岛记录编辑与添加 </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>海魂路1号</Address><HomePage></HomePage><E-Mail>master</E-Mail><TelePhone>(0989)8888888</TelePhone><Grade>五星级</Grade> 软件开发网 </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数据岛中添加记录-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. 软件开发网 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数据岛中的数据resortXML.documentElement.childNodes.item(0).getAttribute("code")/读取页面上的XML数据岛中的数据resortXML.documentElement.childNodes0.getAttribute("code")/读取页面上的XML数据岛中的数据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.动态设置事件,带参数<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('参数');/-></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方式添加事件处理脚本事,有一个被包装成匿名函数的过程,也就是说onClick="javacript:document.Fo

51、rm.Name.value='test'return false;"被包装成了:functoin anonymous() document.Form.Name.value='test'return false;做为A的成员函数onclick。而href="javascript:document.Form.Name.value='test'void(0);"相当于执行全局语句,这时如果使用return语句会报告在函数外使用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.根据名字解析xml中的节点值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.看一个字符串里面有多少个回车符,返回值是一个数组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执行本机的可执行程序,需设置为可信或者降低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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论