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

下载本文档

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

文档简介

Javascript技巧大集合3171.设置和使用cookie设置与读取 cookies.写入cookie的值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 = new 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 未找到!/172.取月的最后一天function getLastDay(year,month)/取年var new_year = year;/取到下一个月的第一天,注意这里传入的month是从112var new_month = month+;/如果当前是12月,则转至下一年if(month12)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.判断当前的焦点是组中的哪一个for(var i=0;i3;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 canAccess = false; HttpSession session= pageContext.getSession(); if (canAccess) return EVAL_BODY_INCLUDE; else return this.SKIP_BODY; 175.在web.xml中添加定义 guoguo /WEB-INF/abc.tld176.标签库中定义abc.tld1.01.1hrguoguoExtra 3 Tag Librarymytagcom.baosight.view.utils.Mytag id2 true true177.在使用自定义标签的页面中加入自己定义的标签,/自己定义标签178.显示带边框的集查询条件dfdfdf/179.【文件(F)】菜单中的命令的实现1、打开命令的实现格式:document.execCommand(open)说明这跟VB等编程设计中的webbrowser控件中的命令有些相似,大家也可依此琢磨琢磨。举例在之间加入:打开2、使用 记事本 编辑命令的实现格式:location.replace(view-source:+location)说明打开记事本,在记事本中显示该网页的源代码。举例在之间加入:使用 记事本编辑3、另存为命令的实现格式:document.execCommand(saveAs)说明将该网页保存到本地盘的其它目录!举例在之间加入:另存为4、打印命令的实现格式:document.execCommand(print)说明当然,你必须装了打印机!举例在之间加入:打印5、关闭命令的实现格式:window.close();return false说明将关闭本窗口。举例在之间加入:关闭本窗口180.【编辑(E)】菜单中的命令的实现全选命令的实现格式:document.execCommand(selectAll)说明将选种网页中的全部内容!举例在之间加入:全选181.【查看(V)】菜单中的命令的实现1、刷新命令的实现格式:location.reload() 或 history.go(0)说明浏览器重新打开本页。举例在之间加入:刷新或加入:刷新2、源文件命令的实现格式:location.replace(view-source:+location)说明查看该网页的源代码。举例在之间加入:查看源文件3、全屏显示命令的实现格式:window.open(document.location, url, fullscreen)说明全屏显示本页。举例在之间加入:全屏显示182.【收藏(A)】菜单中的命令的实现1、添加到收藏夹命令的实现格式:window.external.AddFavorite(url, “网站名”)说明将本页添加到收藏夹。举例在之间加入:添加到收藏夹2、整理收藏夹命令的实现格式:window.external.showBrowserUI(OrganizeFavorites,null)说明打开整理收藏夹对话框。举例在之间加入:整理收藏夹183.【工具(T)】菜单中的命令的实现internet选项命令的实现格式:window.external.showBrowserUI(PrivacySettings,null)说明打开internet选项对话框。举例在之间加入:internet选项184.【工具栏】中的命令的实现1、前进命令的实现格式history.go(1) 或 history.forward()说明浏览器打开后一个页面。举例在之间加入:前进或加入:前进2、后退命令的实现格式:history.go(-1) 或 history.back()说明浏览器返回上一个已浏览的页面。举例在之间加入:后退或加入:后退3、刷新命令的实现格式:document.reload() 或 history.go(0)说明浏览器重新打开本页。举例在之间加入:刷新或加入:刷新185.其它命令的实现定时关闭本窗口命令的实现格式:settimeout(window.close(),关闭的时间)说明将关闭本窗口。举例在之间加入:3秒关闭本窗口【附】为了方便读者,下面将列出所有实例代码,你可以把它们放到一个html文件中,然后预览效果。打开使用 记事本编辑另存为打印关闭本窗口全选 软件开发网 刷新 刷新查看源文件全屏显示添加到收藏夹整理收藏夹internet选项前进1前进2后退1后退2 3秒关闭本窗口186.给DHTML中的标签添加一个新的属性,可以随意加/187.xmlhttp技术 此方法是通过XMLHTTP对象从服务器获取XML文档,示例如下。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文档/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.给下拉框分组锂 (Li)纳 (Na)钾 (K)氟 (F)氯 (Cl)溴 (Br)/191.加注音基准文本注音文本/192.加删除线此文本将带删除线显示。/193.取frame中的event事件document.frames(workspace).event.keyCode/194.是弹出方法的定义Stotype.trim=function()return this.replace(/(s*)|(s*$)/g, );alert( .trim)/195.防止网页被包含if (window != window.top)top.location.href = location.href;/196.让网页一直在frame里面if(window=window.top)document.body.innerHTML=请通过正常方式访问本页面!;/window.close();/197.加为首页function fnSet()oHomePage.setHomePage(location.href);event.returnValue = false;/198.xml数据岛操作HTML中的数据岛中的记录集 软件开发网 HTML中的XML数据岛记录编辑与添加 酒店名称:地址:主页:电子邮件:电话:级别:input id=first TYPE=button value=input id=prev TYPE=button value= onclick=theXMLisland.recordset.moveNext() onclick=theXMLisland.recordset.moveLast()  四海大酒店海魂路1号(0989)8888888五星级 软件开发网 五湖宾馆东平路99号(0979)1111666四星级“大沙漠”宾馆留香路168号(0989)87878788五星级“画眉鸟”大酒店血海飘香路2号(099)9886666五星级 /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 Object 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 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 element. HTML with XML Data Island Within this document is an XML data island. Adventure Works Alpine Ski House For an example, you can cut and paste 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 url=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.动态设置事件,带参数/201.将url转化为16进制形式var ret = ;for(var 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 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.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.Form.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.进行页面放大sdsdsdsdsdsdsdsds /209.放置在页面的最右边/210.通过style来控制隔行显示不同颜色trbgcolor:expression(this.bgColor=(this.rowIndex)%2=0 )? white : yellow);     /211.全屏最大化newwindow=window.open(,scrollbars)if (document.all)newwindow.moveTo(0,0)newwindow.resizeTo(screen.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的值/library/default.asp?url=/library/en-us/xmlsdk/html/5996c682-3472-4b03-9fb0-1e08fcccdf35.asp/214.看一个字符串里面有多少个回车符,返回值是一个数组var s=value.match(/n/g);if(s)if(s.length=9)alert(10行了);return false;/215.获得asc码var s=aa;alert(s.charCodeAt(1)/216.文字居右对齐/217.判断一个方法是否存在function pageCallback(response)alert(response);if(pageCallback)alert(1)/218.判断一个变量是否定义if(typeof(a)=undefined)alert()/219.javascript执行本机的可执行程序,需设置为可信或者降低IE安全级别 function exec (command) window.oldOnError = window.onerror; window._command = command; window.onerror = function (err) if (err.indexOf(utomation) != -1) alert(命令已经被用户禁止!); return true; else return false; ; var wsh = new ActiveXObject(WScript.Shell); if (wsh) wsh.Run(command); window.onerror = window.oldOnError;调用方式测试/220.弹出新页面,关闭旧页面,不弹出提示框var w=screen.availWidth-10; var h=screen.availHeight-10; var swin=window.open(/mc/mc/message_management.jsp,BGSMbest,scrollbars=yes,status,location=0,menubar=0,to

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论