js代码大全.docx
- 文档编号:4651932
- 上传时间:2023-05-07
- 格式:DOCX
- 页数:107
- 大小:62.40KB
js代码大全.docx
《js代码大全.docx》由会员分享,可在线阅读,更多相关《js代码大全.docx(107页珍藏版)》请在冰点文库上搜索。
js代码大全
WWW.XINYIDAI.NET
1.oncontextmenu="window.event.returnValue=false"将彻底屏蔽鼠标右键,可用于Table
2.取消选取、防止复制 3.不准粘贴: onpaste="returnfalse" 4.防止复制: oncopy="returnfalse;"oncut="returnfalse;" 5.IE地址栏前换成自己的图标,先做一个16*16的icon(图标文件),保存为favicon.ico。 把这个图标文件上传到相应目录下。 6.可以在收藏夹中显示出你的图标 7.关闭输入法 disabled"> 8.永远都会带着框架 -- if(window==top)top.location.href="frames.htm";//frames.htm为框架网页 //--> 9.防止被人frame -- if(top.location! =self.location)top.location=self.location; //--> 10.网页将不能被另存为 11.查看网页源代码 onclick="window.location="view-source: "+"""> 12.光标是停在文本框文字的最后 functioncc() { vare=event.srcElement; varr=e.createTextRange(); r.moveStart("character",e.value.length); r.collapse(true); r.select(); } 13.最小化、最大化、关闭窗口 ADB880A6-D8FF-11CF-9377-00AA003B7A11"> ADB880A6-D8FF-11CF-9377-00AA003B7A11"> adb880a6-d8ff-11cf-9377-00aa003b7a11"> 14.网页不会被缓存 21: 57GMT"> 或者 15. 用来定义同一行内的元素,跟 16.怎样去掉图片链接点击后,图片周围的虚线? 17.在打开的子窗口刷新父窗口 window.opener.location.reload() 18.在页面中如何加入不是满铺的背景图片,拉动页面时背景图不动 body {background-image: url(logo.gif);background-repeat: no-repeat; background-position: center;background-attachment: fixed} 19.TEXTAREA自适应文字行数 20.选择了哪一个Radio functioncheckme(){ for(vari=0;i if(radios[i].checked){ window.alert(radios[i].value); } } } 21.脚本永不出错 --Hide functionkillErrors(){ returntrue; } window.onerror=killErrors; //--> 22.ENTER键可以让光标移到下一个输入框 23.网页是否被检索 其中属性值有以下一些: 属性值为"all": 文件将被检索,且页上链接可被查询; 属性值为"none": 文件不被检索,而且不查询页上的链接; 属性值为"index": 文件将被检索; 属性值为"follow": 查询页上的链接; 属性值为"noindex": 文件不检索,但可被查询链接; 属性值为"nofollow": 文件不被检索,但可查询页上的链接。 24.colgroup标签--表示对HTML表格进行结构化的分区,在此分区中可以通过使用col定义每列表格的样式。 .yellow{ color: #CCCC33; font-size: 36px; } .blue{ color: #3399CC; font-size: 12px; } 25.格式化数字 /** *格式化数字显示方式 *@paramnum *@parampattern'#,##0.00''#,##0.##''000000' */ functionformatNumber(num,pattern){ varstrarr=num? num.toString().split('.'): ['0']; varfmtarr=pattern? pattern.split('.'): ['']; varretstr=''; //整数部分 varstr=strarr[0]; varfmt=fmtarr[0]; vari=str.length-1; varcomma=false; for(varf=fmt.length-1;f>=0;f--){ switch(fmt.substr(f,1)){ case'#': if(i>=0)retstr=str.substr(i--,1)+retstr; break; case'0': if(i>=0)retstr=str.substr(i--,1)+retstr; elseretstr='0'+retstr; break; case',': comma=true; retstr=','+retstr; break; } } if(i>=0){ if(comma){ varl=str.length; for(;i>=0;i--){ retstr=str.substr(i,1)+retstr; if(i>0&&((l-i)%3)==0)retstr=','+retstr; } } elseretstr=str.substr(0,i+1)+retstr; } retstr=retstr+'.'; //处理小数部分 str=strarr.length>1? strarr[1]: ''; fmt=fmtarr.length>1? fmtarr[1]: ''; i=0; for(varf=0;f switch(fmt.substr(f,1)){ case'#': if(i break; case'0': if(i elseretstr+='0'; break; } } returnretstr.replace(/^,+/,'').replace(/\.$/,''); } 26.数字验证 /^(-|\+)? \d+$/.test(str)//整数 /^\d+$/.test(str)//大于0的整数 /^-\d+$/.test(str)//负整数的验证 27.时间验证 functionisCorrectTime(str){//like: 13: 04: 06 vara=str.match(/^(\d{1,2})(: )? (\d{1,2})\2(\d{1,2})$/); if(a==null){alert('输入的参数不是时间格式');returnfalse;} if(a[1]>24||a[3]>60||a[4]>60){ alert("时间格式不对"); returnfalse } returntrue; } functionisCorrectDate(str){//2003-12-05 varr=str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/); if(r==null)returnfalse; vard=newDate(r[1],r[3]-1,r[4]); return(d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]); } functionisCorrectDateTime(str){//2003-12-0513: 04: 06 varreg=/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})(\d{1,2}): (\d{1,2}): (\d{1,2})$/; varr=str.match(reg); if(r==null)returnfalse; vard=newDate(r[1],r[3]-1,r[4],r[5],r[6],r[7]); return(d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]&&d.getHours()==r[5]&&d.getMinutes()==r[6]&&d.getSeconds()==r[7]); } 28.去掉前后空白 this.value.replace(/^\s+|\s+$/g,'')=='') 29.操作select if(objselect.selectedIndex>-1){alert('selected');}//是否有选中 objselect.options[objselect.selectedIndex]=null;//删除被选中的项 objselect.options[objselect.length]=newOption("text","value");//增加项 objselect.options[objselect.selectedIndex].text;//得到所选择项的文本 objselect.options[objselect.selectedIndex].value;//得到所选择项的值 document.getElementByid("el").tabIndex=1;//焦点顺序 30.添加到收藏夹: window.external.AddFavorite(''); 31.模态对话框 window.showModelessDialog()方法用来创建一个显示HTML内容的非模态对话框。 window.showModalDialog()方法用来创建一个显示HTML内容的模态对话框,由于 是对话框,因此它并没有一般用window.open()打开的窗口的所有属性。 只是,FireFox浏览器中不支持showmodaldialog(),用window.open。 在Firefox下,window.open的参数中,sFeature多了一些功能设定,要让FireFox下开启的窗口跟IE的showModalDialog一样的话,只要在sFeatures中加个modal=yes就可以了,也许可能是出于安全考虑modal=yes打开的并不是模式窗口。 -- functionshowDialog(url){ if(document.all){//IE feature="dialogWidth: 300px;dialogHeight: 200px;status: no;help: no"; window.showModalDialog(url,null,feature); }else{ //modelessDialog可以将modal换成dialog=yes feature="width=300,height=200,menubar=no,toolbar=no,location=no,"; feature+="scrollbars=no,status=no,modal=yes"; window.open(url,null,feature); } } //--> 32.屏蔽打印按钮 -- @mediaprint{ .disp{ display: none; } } --> 33.动态改变CSS functionchangeLinkCss(url){ varlink_css=document.getElementsByTagName('link'); for(vari=0;i if(link_css[i].rel.toLowerCase()=='stylesheet'){ link_css[i].href=url; } } } 34.置下一元素焦点 functionsetNextFocus(){ varsrcObj=event.srcElement; varlen=document.all.length; varidx=-1; for(vari=0;i varcurObj=document.all[i]; if(curObj==srcObj){ idx=i; break; } } if(idx! =-1&&idx for(varj=idx+1;j if(checkTags(document.all[j])){ document.all[j].focus(); return; } } } } functioncheckTags(obj){ if(obj.readOnly==true||obj.disabled==true){returnfalse;} vartag_name=obj.tagName; varel_tags=['select','input','textarea']; for(vari=0;i if(el_tags[i]==tag_name.toLowerCase()){ returntrue; } } returnfalse; } 35.获得当前目录路径 functiongetCurrentDirectory(){ varlocHref=location.href; varlocArray=locHref.split("/"); /**这里测试locArray效果** for(xinlocArray){ document.write("locArray["); document.write(x+"]: "); document.write(locArray[x]+" } **/ deletelocArray[locArray.length-1]; vardirTxt=locArray.join("/"); returndirTxt; } document.write(getCurrentDirectory()); 36.清空file域 innerHTML设置或获取位于对象起始和结束标签内的HTML outerHTML设置或获取对象及其内容的HTML形式 innerText设置或获取位于对象起始和结束标签内的文本 outerText设置(包括标签)或获取(不包括标签)对象的文本 functionClean(){ varobj=document.getElementById("UpFile"); obj.outerHTML=obj.outerHTML; } 37.js之arguments 使用JavaScript函数内置的arguments可以遍历所有传入的参数。 arguments有个callee属性,可以调用arguments自身所在的函数。 也就是说,可以通过这个属性递归调用函数自身。 functionsum(){ vartotal=0; for(vari=0;i total+=arguments[i]; } alert(total); } sum(1,2); sum(1,2,3); functionsum(n){ if(n<=1){ return1; } returnn+arguments.callee(n-1);//递归调用自身 } alert(sum(100)); 38.document.execCommand() 如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。no .com域名的数量 .cn域名的数量 .net域名的数量 域名的数量 2003年 1000 2000 3000 4000
");