




已阅读5页,还剩27页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
常用的一些javascript小技巧事件源对象phpevent.srcElement.tagNameevent.srcElement.type/php捕获释放phpevent.srcElement.setCapture();event.srcElement.releaseCapture();/php事件按键phpevent.keyCodeevent.shiftKeyevent.altKeyevent.ctrlKey/php事件返回值phpevent.returnValue/php鼠标位置 phpevent.x event.y/php 窗体活动元素 phpdocument.activeElement/php 绑定事件phpdocument.captureEvents(Event.KEYDOWN);/php访问窗体元素phpdocument.all(txt).focus();document.all(txt).select();窗体命令 phpdocument.execCommand 窗体COOKIE phpdocument.cookie/php 菜单事件 phpdocument.oncontextmenu 创建元素phpdocument.createElement(SPAN);根据鼠标获得元素:phpdocument.elementFromPoint(event.x, event.y).tagName=TDdocument.elementFromPoint(event.x, event.y).appendChild(ms)/php窗体图片 phpdocument.images索引/php 窗体事件绑定 phpdocument.onmousedown=scrollwindow;/php 元素 phpdocument.窗体.elements索引/php 对象绑定事件phpdocument.all.xxx.detachEvent(onclick,a);/php插件数目 phpnavigator.plugins/php取变量类型phptypeof($js_libpath) = undefined/php下拉框 php下拉框.options索引下拉框.options.length/php查找对象phpdocument.getElementsByName(r1);document.getElementById(id);/php定时phptimer=setInterval(scrollwindow(),delay);clearInterval(timer);/phpUNCODE编码 phpescape() ,unescape/php 父对象phpobj.parentElement(dhtml)obj.parentNode(dom)/php交换表的行phpTableID.moveRow(2,1)/php替换CSS phpdocument.all.css.href = a.css;/php并排显示 phpdisplay:inline/php隐藏焦点 phphidefocus=true/php根据宽度换行 phpstyle=word-break:break-all/php自动刷新 php/php简单邮件 php/php快速转到位置 phpobj.scrollIntoView(true)/php锚 phpanchors/php网页传递参数phplocation.search();/php可编辑 phpobj.contenteditable=true/php执行菜单命令 phpobj.execCommand/php双字节字符 php/x00-xff/php汉字 php/u4e00-u9fa5/php让英文字符串超出表格宽度自动换行 phpword-wrap: break-word; word-break: break-all;/php透明背景 php/php获得style内容 phpobj.style.cssText/phpHTML标签 phpdocument.documentElement.innerHTML/php第一个style标签 phpdocument.styleSheets0/phpstyle标签里的第一个样式 phpdocument.styleSheets0.rules0/php防止点击空链接时,页面往往重置到页首端。phpword/php上一网页源asp: phprequest.servervariables(HTTP_REFERER)/phpjavascript: phpdocument.referrer/php释放内存phpCollectGarbage();/php禁止右键phpdocument.oncontextmenu = function() return false;/php禁止保存php/php禁止选取php/php禁止粘贴php/php地址栏图标php/phpfavicon.ico 名字最好不变16*16的16色,放虚拟目录根目录下 收藏栏图标php/php查看源码php/php关闭输入法php/php自动全选php/phpENTER键可以让光标移到下一个输入框php/php文本框的默认值php/phptitle换行phpobj.title = 123sdfs /php获得时间所代表的微秒phpvar n1 = new Date(2004-10-10.replace(/-/g, /).getTime()/php窗口是否关闭phpwin.closed/phpcheckbox扁平php/php获取选中内容phpdocument.selection.createRange().duplicate().text/php自动完成功能php打开该功能关闭该功能/php窗口最大化php/php无关闭按钮IEphpwindow.open(aa.htm, meizz, fullscreen=7);/php统一编码/解码phpalert(decodeURIComponent(encodeURIComponent(http:/你好.com?as= hehe)encodeURIComponent对:、/、; 和 ?也编码/php表格行指示php/php/各种尺寸phps+=rn网页可见区域宽:+document.body.clientWidth;s+=rn网页可见区域高:+document.body.clientHeight;s+=rn网页可见区域高:+document.body.offsetWeight+(包括边线的宽);s+=rn网页可见区域高:+document.body.offsetHeight+(包括边线的宽);s+=rn网页正文全文宽:+document.body.scrollWidth;s+=rn网页正文全文高:+document.body.scrollHeight;s+=rn网页被卷去的高:+document.body.scrollTop;s+=rn网页被卷去的左:+document.body.scrollLeft;s+=rn网页正文部分上:+window.screenTop;s+=rn网页正文部分左:+window.screenLeft;s+=rn屏幕分辨率的高:+window.screen.height;s+=rn屏幕分辨率的宽:+window.screen.width;s+=rn屏幕可用工作区高度:+window.screen.availHeight;s+=rn屏幕可用工作区宽度:+window.screen.availWidth;/php/过滤数字php=48&event.keyCode=57|(this.value.indexOf(.)/php/特殊用途php /php/不缓存php/php/正则匹配php匹配中文字符的正则表达式: u4e00-u9fa5匹配双字节字符(包括汉字在内):x00-xff匹配空行的正则表达式:ns| *r匹配HTML标记的正则表达式:/.*|/匹配首尾空格的正则表达式:(s*)|(s*$)(像vbscript那样的trim函数)匹配Email地址的正则表达式:w+(-+.w+)*w+(-.w+)*.w+(-.w+)*匹配网址URL的正则表达式:http:/(w-+.)+w-+(/w- ./?%&=*)?/php以下是例子: 利用正则表达式限制网页表单里的文本框输入内容:php用正则表达式限制只能输入中文:onkeyup=value=value.replace(/u4E00-u9FA5/g,) onbeforepaste=clipboardData.setData(text,clipboardData.getData(text).replace(/u4E00-u9FA5/g,) 1. 用正则表达式限制只能输入全角字符: onkeyup=value=value.replace(/uFF00-uFFFF/g,) onbeforepaste=clipboardData.setData(text,clipboardData.getData(text).replace(/uFF00-uFFFF/g,) 2. 用正则表达式限制只能输入数字:onkeyup=value=value.replace(/d/g,) onbeforepaste=clipboardData.setData(text,clipboardData.getData(text).replace(/d/g,) 3. 用正则表达式限制只能输入数字和英文:onkeyup=value=value.replace(/W/g,) onbeforepaste=clipboardData.setData(text,clipboardData.getData(text).replace(/d/g,)/php/消除图像工具栏php/phpor php/php/无提示关闭phpfunction Close() var ua=navigator.userAgent var ie=navigator.appName=Microsoft Internet Explorer?true:false if(ie) var IEversion=parseFloat(ua.substring(ua.indexOf(MSIE )+5,ua.indexOf(;,ua.indexOf(MSIE ) if(IEversion 5.5) var str= str += ; document.body.insertAdjacentHTML(beforeEnd, str); document.all.noTipClose.Click(); else window.opener =null; window.close(); else window.close() /php/取得控件得绝对位置(1) phpfunction getoffset(e) var t=e.offsetTop;var l=e.offsetLeft;while(e=e.offsetParent) t+=e.offsetTop; l+=e.offsetLeft;var rec = new Array(1); rec0= t; rec1 = l; return rec /php/获得控件的绝对位置(2)phpoRect = obj.getBoundingClientRect(); oRect.left oRect./php/最小化,最大化,关闭php/php/光标停在文字最后php function cc() var e = event.srcElement; var r =e.createTextRange(); r.moveStart(character,e.value.length); r.collapse(true); r.select(); /php/页面进入和退出的特效进入页面php/php推出页面php/php这个是页面被载入和调出时的一些特效。duration表示特效的持续时间,以秒为单位。transition表示使 用哪种特效,取值为1-23: 0 矩形缩小 1 矩形扩大 2 圆形缩小 3 圆形扩大 4 下到上刷新 5 上到下刷新 6 左到右刷新 7 右到左刷新 8 竖百叶窗 9 横百叶窗 10 错位横百叶窗 11 错位竖百叶窗 12 点扩散 13 左右到中间刷新 14 中间到左右刷新 15 中间到上下 16 上下到中间 17 右下到左上 18 右上到左下 19 左上到右下 20 左下到右上 21 横条 22 竖条 23 /网页是否被检索php其中属性值有以下一些: 属性值为all: 文件将被检索,且页上链接可被查询; 属性值为none: 文件不被检索,而且不查询页上的链接; 属性值为index: 文件将被检索; 属性值为follow: 查询页上的链接; 属性值为noindex: 文件不检索,但可被查询链接; 属性值为nofollow:/php/打印分页phppage1page2/php/设置打印php function window.onload() / - advanced features factory.printing.SetMarginMeasure(2) / measure margins in inches factory.printing.SetPageRange(false, 1, 3) / need pages from 1 to 3 factory.printing.printer = HP DeskJet 870C factory.printing.copies = 2 factory.printing.collate = true factory.printing.paperSize = A4 factory.printing.paperSource = Manual feed / - basic features factory.printing.header = 居左显示&b居中显示&b居右显示页码,第&p页/共&P页 factory.printing.footer = (自定义页脚) factory.printing.portrait = false factory.printing.leftMargin = 0.75 factory.printing.topMargin = 1.5 factory.printing.rightMargin = 0.75 factory.printing.bottomMargin = 1.5 function Print(frame) factory.printing.Print(true, frame) / print with prompt 具体使用手册,更多信息,点这里/php/自带的打印预览phpWebBrowser.ExecWB(1,1) 打开Web.ExecWB(2,1) 关闭现在所有的IE窗口,并打开一个新窗口Web.ExecWB(4,1) 保存网页Web.ExecWB(6,1) 打印Web.ExecWB(7,1) 打印预览Web.ExecWB(8,1) 打印页面设置Web.ExecWB(10,1) 查看页面属性Web.ExecWB(15,1) 好像是撤销,有待确认Web.ExecWB(17,1) 全选Web.ExecWB(22,1) 刷新Web.ExecWB(45,1) 关闭窗体无提示.Noprintdisplay:none;.PageNextpage-break-after: always; /php/去掉打印时的页眉页脚php var HKEY_Root,HKEY_Path,HKEY_Key; HKEY_Root=HKEY_CURRENT_USER; HKEY_Path=SoftwareMicrosoftInternet ExplorerPageSetup; /设置网页打印的页眉页脚为空 function PageSetup_Null() try var Wsh=new ActiveXObject(WScript.Shell); HKEY_Key=header; Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,); HKEY_Key=footer; Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,); catch(e) /设置网页打印的页眉页脚为默认值 functionPageSetup_Default() try var Wsh=new ActiveXObject(WScript.Shell); HKEY_Key=header; Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,&w&b页码,&p/&P); HKEY_Key=footer; Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,&u&b&d); catch(e) /php/浏览器验证phpfunction checkBrowser() this.ver=navigator.appVersionthis.dom=document.getElementById?1:0this.ie6=(this.ver.indexOf(MSIE 6)-1 & this.dom)?1:0;this.ie5=(this.ver.indexOf(MSIE 5)-1 & this.dom)?1:0;this.ie4=(document.all & !this.dom)?1:0;this.ns5=(this.dom & parseInt(this.ver) = 5) ?1:0;this.ns4=(document.layers & !this.dom)?1:0;this.mac=(this.ver.indexOf(Mac) -1) ?1:0;this.ope=(navigator.userAgent.indexOf(Opera)-1);this.ie=(this.ie6 | this.ie5 | this.ie4)this.ns=(this.ns4 | this.ns5)this.bw=(this.ie6 | this.ie5 | this.ie4 | this.ns5 | this.ns4 | this.mac | this.ope)this.nbw=(!this.bw)return this; /php/计算内容宽和高php functiontest(obj) varrange=obj.createTextRange(); alert(内容区宽度:+range.boundingWidth +pxrn内容区高度:+ range.boundingHeight+px); sdf /php/无模式的提示框phpfunction modelessAlert(Msg) window.showModelessDialog(javascript:alert(+escape(Msg)+);window.close();,status:no;resizable:no;help:no;dialogHeight:height:30px;dialogHeight:40px;); /php/屏蔽按键php 屏蔽鼠标右键、Ctrl+N、Shift+F10、Alt+F4、F11、F5刷新、退格键 !- /屏蔽鼠标右键、Ctrl+N、Shift+F10、F11、F5刷新、退格键 /Author: meizz(梅花雨) 2002-6-18 function document.oncontextmenu()event.returnValue=false;/屏蔽鼠标右键 function window.onhelp()return false /屏蔽F1帮助 function document.onkeydown() if (window.event.altKey)& (window.event.keyCode=37)| /屏蔽 Alt+ 方向键 (window.event.keyCode=39) /屏蔽 Alt+ 方向键 alert(不准你使用ALT+方向键前进或后退网页!); event.returnValue=false; /* 注:这还不是真正地屏蔽 Alt+ 方向键, 因为 Alt+ 方向键弹出警告框时,按住 Alt 键不放, 用鼠标点掉警告框,这种屏蔽方法就失效了。以后若 有哪位高手有真正屏蔽 Alt 键的方法,请告知。*/ if (event.keyCode=8)| /屏蔽退格删除键 (event.keyCode=116)| /屏蔽 F5 刷新键 (event.ctrlKey & event.keyCode=82) /Ctrl + R event.keyCode=0; event.returnValue=false; if (event.keyCode=122)event.keyCode=0;event.returnValue=false;/屏蔽F11 if (event.ctrlKey & event.keyCode=78) event.returnValue=false; /屏蔽 Ctrl+n if (event.shiftKey & event.keyCode=121)event.returnValue=false;/屏蔽 shift+F10 if (window.event.srcElement.tagName = A & window.event.shiftKey) window.event.returnValue = false; /屏蔽 shift 加鼠标左键新开一网页 if (window.event.altKey)&(window.event.keyCode=115) /屏蔽Alt+F4 window.showModelessDialog(about:blank,dialogWidth:1px;dialogheight:1px); return false; 屏蔽鼠标右键、Ctrl+N、Shift+F10、Alt+F4、F11、F5刷新、退格键 /php/屏蔽打印php media print * display:none /php/移动的图层,拖动1.phpmeizz var Obj; function MouseDown(obj) Obj=obj; Obj.setCapture(); Obj.l=event.x-Obj.style.pixelLeft; Obj.t=event.y-Obj.style.pixelTop; function MouseMove() if(Obj!=null) Obj.style.left = event.x-Obj.l; Obj.style.top = e
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论