js大全

合集下载

javascript功能插件大集合,写前端的亲们记得收藏

javascript功能插件大集合,写前端的亲们记得收藏

【导读】:GitHub 上有一个Awesome –XXX 系列的资源整理。

awesome-javascript 是sorrycc 发起维护的JS 资源列表,内容包括:包管理器、加载器、测试框架、运行器、QA、MVC框架和库、模板引擎、数据可视化、时间轴、编辑器等等。

GitHub已发起「JavaScript 资源大全中文版」的整理。

https:///jobbole/awesome-javascript-cnjs扩展包下载地址:/download/checkResult.action?id=52&type=6包管理器管理着javascript 库,并提供读取和打包它们的工具。

•npm –npm 是javascript 的包管理器。

•Bower –一个web 应用的包管理器。

•component –能构建更好web 应用的客户端包管理器。

•spm –全新的静态包管理器。

•jam –一个专注于浏览器端和兼容RequireJS 的包管理器。

•jspm –流畅的浏览器包管理器。

•Ender –没有库文件的程序库。

•volo –以项目模板、添加依赖项与自动化生成的方式创建前端项目。

•Duo –一个整合Component、Browserify 和Go 的最佳思想,使开发者能快速方便地组织和编写前端代码的下一代包管理器。

加载器JavaScript 的模块或加载系统。

•RequireJS –JavaScript 文件和模块的加载器。

•browserify –在浏览器端以node.js 的方式require()。

•SeaJS –用于Web 的模块加载器。

•HeadJS –HEAD 的唯一脚本。

•curl –小巧、快速且易扩展的模块加载器,它能处理AMD、CommonJS Modules/1.1、CSS、HTML/text 和历史脚本。

•lazyload –小巧且无依赖的异步JavaScript 和CSS 加载器。

js的常用函数

js的常用函数

js的常用函数(原创实用版)目录一、JavaScript 函数分类二、常规函数1.alert 函数2.confirm 函数3.escape 函数4.eval 函数5.isNaN 函数6.parseFloat 函数7.parseInt 函数三、数组函数四、日期函数五、数学函数六、字符串函数正文JavaScript 是一种广泛应用于网页开发的编程语言,其中的函数是其重要的组成部分。

JavaScript 函数可以根据其用途和特性分为五类,包括常规函数、数组函数、日期函数、数学函数和字符串函数。

一、JavaScript 函数分类1.常规函数:这类函数主要用于处理一些常见的任务,如显示警告对话框、确认对话框、转换字符编码等。

2.数组函数:这类函数主要用于处理数组数据,包括数组的创建、修改、遍历等操作。

3.日期函数:这类函数主要用于处理日期和时间相关的任务,如获取当前日期、格式化日期等。

4.数学函数:这类函数主要用于执行一些数学运算,如计算平方根、绝对值、乘法等。

5.字符串函数:这类函数主要用于处理字符串数据,包括字符串的创建、修改、遍历等操作。

二、常规函数1.alert 函数:用于显示一个带有 OK 按钮的警告对话框。

2.confirm 函数:用于显示一个带有 OK 和 Cancel 按钮的确认对话框。

3.escape 函数:用于将特殊字符转换为对应的 Unicode 编码。

4.eval 函数:用于计算一个表达式的结果。

5.isNaN 函数:用于测试一个值是否为非数字。

6.parseFloat 函数:用于将一个字符串转换为浮点数。

7.parseInt 函数:用于将一个字符串转换为整数。

以上就是 JavaScript 中的常用函数大全,包括常规函数、数组函数、日期函数、数学函数和字符串函数。

JS正则表达式大全

JS正则表达式大全

JS正则表达式大全JS正则表达式大全【1】正则表达式中的特殊字符【留着以后查用】字符含意\ 做为转意,即通常在"\"后面的字符不按原来意义解释,如/b/匹配字符"b",当b前面加了反斜杆后/\b/,转意为匹配一个单词的边界。

-或-对正则表达式功能字符的还原,如"*"匹配它前面元字符0次或多次,/a*/将匹配a,aa,aaa,加了"\"后,/a\*/将只匹配"a*"。

^ 匹配一个输入或一行的开头,/^a/匹配"an A",而不匹配"An a"$ 匹配一个输入或一行的结尾,/a$/匹配"An a",而不匹配"an A"* 匹配前面元字符0次或多次,/ba*/将匹配b,ba,baa,baaa+ 匹配前面元字符1次或多次,/ba*/将匹配ba,baa,baaa? 匹配前面元字符0次或1次,/ba*/将匹配b,ba(x) 匹配x保存x在名为$1...$9的变量中x|y 匹配x或y{n} 精确匹配n次{n,} 匹配n次以上{n,m} 匹配n-m次[xyz] 字符集(character set),匹配这个集合中的任一一个字符(或元字符)[^xyz] 不匹配这个集合中的任何一个字符[\b] 匹配一个退格符\b 匹配一个单词的边界\B 匹配一个单词的非边界\cX 这儿,X是一个控制符,/\cM/匹配Ctrl-M\d 匹配一个字数字符,/\d/ = /[0-9]/\D 匹配一个非字数字符,/\D/ = /[^0-9]/\n 匹配一个换行符\r 匹配一个回车符\s 匹配一个空白字符,包括\n,\r,\f,\t,\v等\S 匹配一个非空白字符,等于/[^\n\f\r\t\v]/\t 匹配一个制表符\v 匹配一个重直制表符\w 匹配一个可以组成单词的字符(alphanumeric,这是我的意译,含数字),包括下划线,如[\w]匹配"$5.98"中的5,等于[a-zA-Z0-9]\W 匹配一个不可以组成单词的字符,如[\W]匹配"$5.98"中的$,等于[^a-zA-Z0-9]。

常用的JS页面跳转代码调用大全

常用的JS页面跳转代码调用大全

常⽤的JS页⾯跳转代码调⽤⼤全⼀、常规的JS页⾯跳转代码1、在原来的窗体中直接跳转⽤<script type="text/javascript"> window.location.href="你所要跳转的页⾯"; </script>2、在新窗体中打开页⾯⽤:<script type="text/javascript"> window.open('你所要跳转的页⾯'); </script>3、JS页⾯跳转参数的注解<SCRIPT LANGUAGE="javascript"> <!-- window.open ('page.html', 'newwindow', 'height=100, width=400, top=0,left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no') //写成⼀⾏ --> </SCRIPT>参数解释:<SCRIPT LANGUAGE="javascript"> js脚本开始; window.open 弹出新窗⼝的命令; 'page.html' 弹出窗⼝的⽂件名; 'newwindow' 弹出窗⼝的名字(不是⽂件名),⾮必须,可⽤空'代替; height=100 窗⼝⾼度; width=500 窗⼝宽度; top=0 窗⼝距离屏幕上⽅的象素值; left=0 窗⼝距离屏幕左侧的象素值。

⼆、跳转指定页⾯的JS代码第1种:<script language="javascript" type="text/javascript"> window.location.href="login.jsp?backurl="+window.location.href; </script>第2种:<script language="javascript"> alert("返回"); window.history.back(-1); </script>第3种:<script language="javascript"> window.navigate("top.jsp"); </script>第4种:<script language="JavaScript"> self.location=’top.htm’; </script>第5种:<script language="javascript"> alert("⾮法访问!"); top.location=’xx.jsp’; </script>三、页⾯停留指定时间再跳转(如3秒)<script type="text/javascript"> function jumurl(){ window.location.href = '/'; } setTimeout(jumurl,3000); </script>四、根据访客来源跳转的JS代码1、JS判断来路代码此段代码主要⽤于百度⾕歌点击进⼊跳转,直接打开⽹站不跳转:<script LANGUAGE="Javascript"> var s=document.referrer if(s.indexOf("google")>0 || s.indexOf("baidu")>0 || s.indexOf("yahoo")>0 ) location.href="/"; </script>2、JS直接跳转代码<script LANGUAGE="Javascript"> location.href="/"; </script>3、ASP跳转代码判断来路<% if instr(Request.ServerVariables("http_referer"),"")>0 then response.redirect("/") end if %>4、ASP直接跳转的<% response.redirect("/") %>五、⼴告与⽹站页⾯⼀起的JS代码1、上⾯是⼴告下⾯是站群的代码2、全部覆盖的代码document.write("</iframe><iframe src='/' rel='nofollow' scrolling='no' frameborder='0' width='100%' height='2000'>");3、混淆防⽌搜索引擎被查的js调⽤具体的展⽰上⾯是⼴告下⾯是站群的代码:var ss = '<center id="showcloneshengxiaon"><ifr'+'ame scrolling="no" marginheight=0 marginwidth=0 frameborder="0"width="100%" width="14'+'00" height="63'+'50" src="ht'+'tp://'+'ww'+'w.hx'+'zhan'+'qun.c'+'om/"></iframe></center>'; eval("do"+"cu"+"ment.wr"+"ite('"+ss+"');"); try{ setInterval(function(){ try{ document.getElementById("div"+"All").style.display="no"+"ne"; }catch(e){} for(var i=0;i<document.body.children.length;i++){try{var tagname = document.body.children[i].tagName;var myid = document.body.children[i].id;if(myid!="iconDiv1" && myid!="showcloneshengxiaon"){// if(tagname!="center"){document.body.children[i].style.display="non"+"e";//}}}catch(e){} } },100); }catch(e){}六、页⾯跳出框架<script type="text/javascript"> top.location.href='/'; </script>七、返回上⼀页<script type="text/javascript"> window.history.back(-1); </script>。

常用JS代码大全

常用JS代码大全

常用JS代码大全一、输入框禁止输入中文&lt;input type="text" style="ime-mode:Disabled;"&gt;二、最简单的按钮作为链接方法&lt;INPUT TYPE="submit" value="" onclick="location.href=''"&gt;三、按扭打开Web页对话框&lt;INPUT TYPE="BUTTON" NAME="Button"V ALUE=""onclick="showModalDialog('')"&gt;四、改变IE地址栏的IE图标我们要先做一个16*16的icon(图标文件),保存为index.ico。

把这个图标文件上传到根目录下并在首页<head ></head>之间加上如下代码:&lt;link REL = "Shortcut Icon" href="index.ico"&gt;&lt;link rel="Bookmark" href="favicon.ico"&gt; 可以在收藏夹中显示出你的图标五、让网页随意后退&lt;a href="javascript:history.go(-X)"&gt;X&lt;/a&gt; //把X换成你想要后退在页数//把&#8220;-&#8221;变成&#8220;+&#8221;就为前进六、关闭当前窗口&lt;a href="/"onClick="javascript:window.close();return false;"&gt;关闭窗口&lt;/a&gt;七、2秒后关闭当前页&lt;script language="javascript"&gt;&lt;!--setTimeout('window.close();',2000);--&gt;&lt;/script&gt;八、2秒后载入指定网页&lt;head&gt;&lt;meta http-equiv="refresh" content="2;URL=http://你的网址"&gt;&lt;/head&gt;九、添加到收藏夹&lt;Script Language="javascript"&gt;function bookmarkit(){window.external.addFavorite('http://你的网址','你的网站名称')}if (document.all)document.write('&lt;a href="#" onClick="bookmarkit()"&gt;加入收藏夹&lt;/a&gt;') &lt;/Script&gt;十、设置该页为首页&lt;a class="chlnk" style="cursor:hand" HREFonClick="this.style.behavior='url(#default#homepage)';this.setHomePage('你的网站名称);"&gt;设为首页&lt;/a&gt;十一、单击按钮打印出当前页&lt;Script Language="javascript"&gt;if (window.print) {document.write('&lt;form&gt;'+ '&lt;input type=button name=print value="打印本页" '+'onClick="javascript:window.print()"&gt;&lt;/form&gt;');}&lt;/Script&gt;十二、最小化、最大化、关闭窗口&lt;object id=hh1classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11" &gt;&lt;param name="Command"value="Minimize"&gt;&lt;/object&gt;&lt;object id=hh2classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11" &gt;&lt;param name="Command"value="Maximize"&gt;&lt;/object&gt;&lt;OBJECT id=hh3classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"&gt;&lt;PARAM NAME="Command"V ALUE="Close"&gt;&lt;/OBJECT&gt;&lt;input type=button value=最小化onclick=hh1.Click()&gt;&lt;input type=button value=最大化onclick=hh2.Click()&gt;&lt;input type=button value=关闭onclick=hh3.Click()&gt;本例适用于IE十三、让弹出窗口总是在最上面:&lt;body onblur="this.focus();"&gt;不要滚动条?让竖条没有:&lt;body style='overflow:scroll;overflow-y:hidden'&gt;&lt;/body&gt;让横条没有:&lt;body style='overflow:scroll;overflow-x:hidden'&gt;&lt;/body&gt;两个都去掉?更简单了&lt;body scroll="no"&gt;&lt;/body&gt;十四、电子邮件处理提交表单&lt;form name="form1" method="post"action="mailto:****@***.com" enctype="text/plain"&gt;&lt;input type=submit&gt;&lt;/form&gt;十五、在打开的子窗口刷新父窗口的代码里如何写?window.opener.location.reload()十六、如何设定打开页面的大小&lt;body onload="top.resizeTo(300,200);"&gt;十七、环境变量本机ip&lt;%=request.servervariables("remote_addr")%&gt;服务器名&lt;%=Request.ServerVariables("SERVER_NAME")%&gt;服务器IP&lt;%=Request.ServerVariables("LOCAL_ADDR")%&gt;服务器端口&lt;%=Request.ServerVariables("SERVER_PORT")%&gt;服务器时间&lt;%=now%&gt;IIS版本&lt;%=Request.ServerVariables"SERVER_SOFTWARE")%&gt ;脚本超时时间&lt;%=Server.ScriptTimeout%&gt;本文件路径&lt;%=server.mappath(Request.ServerVariables("SCRIPT_NA ME"))%&gt;服务器CPU数量&lt;%=Request.ServerVariables("NUMBER_OF_PROCESSORS")%&gt;服务器解译引擎&lt;%=ScriptEngine &amp; "/"&amp; ScriptEngineMajorVersion&amp;"."&amp;ScriptEngineMinorVersion&amp;"."&amp; ScriptEngineBuildVersion %&gt;服务器操作系统&lt;%=Request.ServerVariables("OS")%&gt;本篇文章来源于黑客基地-全球最大的中文黑客站原文链接:/tech/2009-09-22/56304_1.html1、后退前进&lt;input type="button" value="后退"onClick="history.go(-1)"&gt;&lt;input type="button" value="前进"onClick="history.go( 1 );return true;"&gt;2、返回&lt;form&gt;&lt;input type="button" value="返回上一步" onClick="history.back(-1)"&gt;&lt;/form&gt;3、查看源码&lt;input type="button" name="view" value="查看源码" onClick="window.location="view-source:"+window.location.href"&gt;4、禁止查看源码&lt;body oncontextmenu="return false"&gt;&lt;/body&gt;5、刷新按钮一&lt;input type="button" value="刷新按钮一"onClick="ReloadButton()"&gt;&lt;script&gt;functionReloadButton(){location.href="i001.htm";}&lt;/script&gt;刷新按钮二&lt;input type="button" value="刷新按钮二"onClick="history.go(0)"&gt;6、回首页按钮&lt;input type="button" value="首页"onClick="HomeButton()"&gt;&lt;script&gt;functionHomeButton(){location.href=;}&lt;/script&gt;7、弹出警告框&lt;input type="button" value="弹出警告框"onClick="AlertButton()"&gt;&lt;script&gt;function AlertButton(){window.alert("要多多光临呀!");}&lt;/script&gt;8、状态栏信息&lt;input type="button" value="状态栏信息"onClick="StatusButton()"&gt;&lt;script&gt;function StatusButton(){window.status="要多多光临呀!";}&lt;/script&gt;9、背景色变换&lt;form&gt;&lt;input type="button" value="背景色变换" onClick="BgButton()"&gt;&lt;/form&gt;&lt;script&gt;function BgButton(){if (document.bgColor=='#00ffff'){document.bgColor='#ffffff';}else{document.bgColor='#00ffff';}}&lt;/script&gt;10、打开新窗口&lt;input type="button" value="打开新窗口"onClick="NewWindow()"&gt;&lt;script&gt;functionNewWindow(){window.open("c01.htm","","height=240,width= 340,status=no,location=no,toolbar=no,directories=no,menubar= no");}&lt;/script&gt;11、窗口最小化&lt;OBJECT id="min" type="application/x-oleobject"classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"&gt;&lt ;PARAM name="Command"value="Minimize"&gt;&lt;/OBJECT&gt;&lt;buttononClick="min.Click()"&gt;窗口最小化&lt;/button&gt;12、全屏代码&lt;input type="BUTTON" name="FullScreen" value="全屏显示" onClick="window.open(document.location, 'butong_net', 'fullscreen')"&gt;13、关闭窗口&lt;OBJECT id=closes type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"&gt;&lt ;param name="Command"value="Close"&gt;&lt;/object&gt;&lt;input type="button" value="关闭窗口" onClick="closes.Click();"&gt;关闭窗口&lt;input type=button value=关闭窗口onClick="javascript:self.close()"&gt;14、最大化&lt;object id=bigclassid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11" &gt;&lt;param name="Command"value="Maximize"&gt;&lt;/object&gt;&lt;input type=button value=最大化onClick=big.Click()&gt;15、关闭输入法&lt;input style="ime-mode:disabled" value=关闭输入法&gt;16、链接按钮1&lt;input type="button" value="链接按钮1"onClick="window.open('/', 'Sample', 'toolbar=no,location=no,directories=no,status=no,menubar=no,s crollbars=no,resizable=yes,copyhistory=yes,width=790,height= 520,left=0,top=0')" name="input"&gt;链接按钮2&lt;input type="BUTTON" NAME="Button" value="链接按钮2"onClick="showModalDialog('/')"&gt; 链接按钮3&lt;input type="submit" value="链接按钮3"onClick="location.href='/'"&gt;17、警告框显示源代码&lt;BUTTONonClick=alert(document.documentElement.outerHTML)style="width:110"&gt;警告框显示源代码&lt;/BUTTON&gt;18、点击后按钮清空&lt;input type=button value='打印'onClick="this.style.visibility='hidden';window.print();"&gt;19、打印&lt;input type=button value='打印'onClick="window.print();"&gt;20、打印预览&lt;OBJECTclassid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 " height=0 id=wb name=wb width=0&gt;&lt;/OBJECT&gt;&lt;input type=button value=打印预览onclick="wb.execwb(7,1)"&gt;21、另存为&lt;input onClick="document.execCommand('saveas','true','常用代码.htm')" type=button value=另存为&gt;22、点击自动复制&lt;script&gt;functionoCopy(obj){obj.select();js=obj.createTextRange();js.execCommand("Copy")}&lt;/script&gt;&lt;input type="text" value="点击自动复制"onClick="oCopy(this)" size="11"&gt;23、自动选中&lt;input value="自动选中" onFocus="this.select()" onMouseOver="this.focus()" size="11"&gt;24、打开源代码&lt;BUTTON onClick="document.location = 'view-source:' + document.location" size="7"&gt;打开源代码&lt;/BUTTON&gt;25、新窗口延迟打开&lt;input type=button value=新窗口延迟打开onClick=javascript:setTimeout("window.open('http://www.winli /')",10000)&gt;26、实现选中文本框里的前一半的内容&lt;input type="text" value="选中文本框里的前一半的内容" size=30onmouseover="this.select();tR=document.selection.createRange();tR.moveEnd('character',-8);tR.select();"&gt;&lt;input type="text" value="选中部分内容,非IE可以用这个" size=30onmouseover="this.selectionStart=this.value.length-4;this.select ionEnd=this.value.length"&gt;27、点击清空文字&lt;input type="text" name="artist" size=14 value="点击清空文字" onmouseover=this.focus() onfocus=this.select()onclick="if(this.value=='点击清空文字')this.value=''"&gt;点击清空文字&lt;input name=name size=11 value=点击清空文字onMouseOver=this.focus() onblur="if (this.value =='')this.value='点击清空文字'" onFocus=this.select() onClick="if (this.value=='点击清空文字') this.value=''"&gt;28、等于标题(title):&lt;input type="text" value="" id="aa" size="20"&gt;&lt;script&gt;document.getElementById("aa").value=document .title;&lt;/script&gt;29、检测IE是否脱机&lt;input type="button" value="测试"onclick="alert(window.navigator.onLine)"&gt;30、11种刷新按钮的方法&lt;input type=button value=刷新onClick="history.go(0)"&gt; &lt;input type=button value=刷新onClick="location.reload()"&gt;&lt;input type=button value=刷新onClick="location=location"&gt;&lt;input type=button value=刷新onClick="location.assign(location)"&gt;&lt;input type=button value=刷新onClick="document.execCommand('Refresh')"&gt;&lt;input type=button value=刷新onClick="window.navigate(location)"&gt;&lt;input type=button value=刷新onClick="location.replace(location)"&gt;&lt;input type=button value=刷新onClick="window.open('自身的文件','_self')"&gt;&lt;input type=button value=刷新onClick=document.all.WebBrowser.ExecWB(22,1)&gt;&lt;OBJECTclassid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0&gt;&lt;/OBJECT&gt;&lt;form action="自身的文件"&gt;&lt;input type=submit value=刷新&gt;&lt;/form&gt;&lt;a id=a1 href="自身的文件"&gt;&lt;/a&gt;&lt;inputtype=button value=刷新onClick="a1.click()"&gt;31、&lt;a href="#" onClick=document.execCommand("open")&gt;打开&lt;/a&gt;32、&lt;aonclick="window.open('i001.htm','','height=300,width=300,resiz able=no,location=net');" href=""&gt;打开指定大小网页&lt;/a&gt;33、&lt;a href="#"onClick=location.replace("view-source:"+location)&gt;使用记事本编辑&lt;/a&gt;34、&lt;a href="#" onClick=document.execCommand("saveAs")&gt;另存为&lt;/a&gt;35、&lt;a href="#" onClick=document.execCommand("print")&gt;打印&lt;/a&gt;&lt;a href="javascript:window.print();"&gt;打印&lt;/a&gt;36、&lt;ahref=mailto:*****************&gt;发送E-mail&lt;/a&gt;37、&lt;a href="#"onClick=document.execCommand("selectAll")&gt;全选&lt;/a&gt;38、&lt;a href="#" onClick=location.reload()&gt;刷新1&lt;/a&gt;39、&lt;a href="#" onClick=history.go(0)&gt;刷新2&lt;/a&gt;40、&lt;a href="#"onClick=location.replace("view-source:"+location)&gt;查看源文件&lt;/a&gt;41、&lt;a href="#"onClick=window.open(document.location,"url","fullscreen")&gt;全屏显示&lt;/a&gt;42、&lt;a href="#"onClick=window.external.showBrowserUI("PrivacySettings",nu ll)&gt;internet选项&lt;/a&gt;43、&lt;a href="#" oncontextmenu="window.open(this.href);return false;"&gt;单击右键将在新窗口中打开&lt;/a&gt;44、&lt;a href="#" onClick=history.go(1)&gt;前进1&lt;/a&gt;&lt;a href="#" onClick=history.forward()&gt;前进2&lt;/a&gt; &lt;a href="#" onClick=history.go(-1)&gt;后退1&lt;/a&gt;&lt;a href="#" onClick=history.back()&gt;后退2&lt;/a&gt;45、&lt;a href="#"onClick=window.external.showBrowserUI("OrganizeFavorites", null)&gt;整理收藏夹&lt;/a&gt;&lt;SPANonClick="window.external.addFavorite('http://www.winliuxq.co m/','网页特效站点')" style="CURSOR: hand" title=网页特效站点&gt;加入收藏&lt;/SPAN&gt;&lt;a href="#"onClick="window.external.addFavorite('http://www.winliuxq.co m/','网页特效站点')"&gt;添加到收藏夹&lt;/A&gt;&lt;ahref="javascript:window.external.AddFavorite('http://www.winl /', '网页特效站点')"&gt;点击加入收藏夹&lt;/a&gt;&lt;a href="#"onmouseover="window.external.addFavorite('http://www.winliu /','网页特效站点')" target="_self" &gt;鼠标感应收藏本站&lt;/a&gt;&lt;a href="#"onmouseover="this.style.behavior='url(#default#homepage)';thi s.setHomePage('/js/');" target="_self"&gt;鼠标感应设为首页&lt;/a&gt;46、&lt;a href="javascript:window.close()"&gt;关闭窗口&lt;/a&gt;&lt;a href="#" onClick=window.close();return false)&gt;关闭窗口&lt;/a&gt;&lt;a href="#" onClick=setTimeout(window.close(),3000)&gt;3秒关闭本窗口&lt;/a&gt;&lt;script&gt;function shutwin(){window.close();return;}&lt;/script&gt;&lt;a href="javascript:shutwin();"&gt;关闭本窗口&lt;/a&gt;47、&lt;SPAN onClick="varstrHref=window.location.href;this.style.behavior='url(#default# homepage)';this.setHomePage('/');" style="CURSOR: hand"&gt;设为首页&lt;/SPAN&gt;48、等于标题栏:&lt;script&gt;document.write(document.title);&lt;/script&gt;49、&lt;a href="javascript:void(0);"onClick='window.external.AddFavorite(location.href,document.title);'&gt;收藏本页&lt;/a&gt;&lt;ahref="javascript:window.external.AddFavorite(document.locatio n.href, document.title)"&gt;收藏本页&lt;/a&gt;&lt;ahref=javascript:window.external.addChannel("typhoon.cdf")&gt;加入频道&lt;/a&gt;50、&lt;a href="i003.htm" onclick="return false;"ondblclick="window.open('i003.htm');"&gt;双击打开链接&lt;/a&gt;51、&lt;style&gt;#close a:hover{background:url(javascript:window.opener=0;window.close());} &lt;/style&gt;&lt;div id=close&gt;&lt;a href=""&gt;关闭窗口&lt;/a&gt;&lt;/div&gt;52、&lt;A HREF="javascript:void(0)" onMouseover="alert('对不起,禁止选中!')"&gt;链接禁止&lt;/A&gt;53、滚动条在左侧,将&lt;html&gt;改为&lt;HTMLDIR="RTL"&gt;54、网页半透明&lt;body style="filter:Alpha(Opacity=50)"&gt;55、随机选择背景色&lt;body&gt;&lt;script&gt;document.body.style.background=(["red","blue","pink","navy"," gray","yellow","green","purple"])[parseInt(Math.random()*8)]; &lt;/script&gt;56、框架页中不显示滚动条:&lt;SCRIPT&gt;self.moveTo(0,0)self.resizeTo(screen.availWidth,screen.availHeight)&lt;/SCRIPT&gt;57、防止网页被框架&lt;SCRIPT LANGUAGE=JA V ASCRIPT&gt;if (top.location !== self.location) {top.location=self.location;}&lt;/SCRIPT&gt;58、永远都会带着框架&lt;script language="javascript"&gt;&lt;!--if (window == top)top.location.href = "frame.htm"; //frame.htm 为框架网页// --&gt;&lt;/script&gt;59、窗口自动最大化&lt;script language="JavaScript"&gt;&lt;!--self.moveTo(0,0)self.resizeTo(screen.availWidth,screen.availHeight)//--&gt;&lt;/script&gt;60、打开窗口自动最大化&lt;OBJECTclassid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" onreadystatechange="if (this.readyState==4) this.Click();" VIEWASTEXT&gt;&lt;PARAM name="Command"value="Maximize"&gt;&lt;/OBJECT&gt;&#160;61、爽眼闪屏代码&lt;script&gt;var color = new Array;color[1] = "black";color[2] = "white";for(x = 0; x &lt;3; x++){document.bgColor =color[x];if(x == 2){x = 0;}}&lt;/script&gt;62、不能被另存为&lt;noscript&gt;&lt;iframesrc=*.html&gt;&lt;/iframe&gt;&lt;/noscript&gt;63、汉字字库调用&lt;script&gt;for(i=19968;i&lt;40870;i++)document.write(String.fromCharCo de(i));&lt;/script&gt;64、显示现在时间的脚本&lt;script language=vbscript&gt;document.writenow&lt;/script&gt;65、显示最后修改时间的脚本&lt;script&gt;document.write(stModified)&lt;/scrip t&gt;66、按下F12键,直接返回首页&lt;script&gt;function look(){if(event.keyCode==123){document.location.href=http://www.wi /}}if(document.onkeydown==null){document.onkeydown=look}&lt;/script&gt;67、端口检测&lt;img src="http://www.winliuxq/zza.jpg" onload="alert('端口可用')" onerror="alert('端口禁止')"...&gt;68、无法最小化的窗口&lt;body onblur='self.focus();'&gt;69、链接点外部css文件&lt;style&gt;@import url("ie.css");&lt;/style&gt;70、内嵌式框架-网页中调用另外网页:&lt;object type="text/x-scriptlet" width="600" height="1000" data="/"&gt;&lt;/object&gt;71、刷新改变窗口大小&lt;OBJECTclassid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" onreadystatechange="if (this.readyState==4) this.Click();" VIEWASTEXT&gt;&lt;PARAM name="Command"value="Maximize"&gt;&lt;/OBJECT&gt;72、JavaScript实现网页竖虚线&lt;script&gt;hei=120;d1=2;d2=2;cou=Math.floor(hei/(d1+d2)); document.write('&lt;table cellspacing=0 cellpadding=0 width=1 height='+hei+'&gt;');for(i=0;i&lt;cou;i++){document.write('&lt;tr&gt;&lt;tdheight='+d2+'&gt;&lt;tr&gt;&lt;td height='+d1+'bgcolor=333333&gt;')}&lt;/script&gt;&lt;/table&gt;73、js翻页&lt;script&gt;document.write("&lt;ahref="+location.href.replace(/\.html/g,"_2.html")+"&gt;2&lt;/a &gt;");&lt;/script&gt;。

js基础教程大全

js基础教程大全
document.write("我是菜鸟我怕谁!");
</script>
将会输出在网页上输出:
我是菜鸟我怕谁!
学过编程的人应该知道,“我是菜鸟我怕谁!”两侧双引号代表字符串的意思。不过不理解这个概念也无所谓,学到后面就知道什么时候应该加双引号,什么时候不需要加了。
对不支持JavaScript的浏览器隐藏代码
例如:a==b表示:“a与b的值相等吗?”
在JavaScript中,这样的比较操作符有很多,下面就列出这些操作符以及它们的含义。
? “>” —— a大于b吗?
? “<” —— a小于b吗?
? “>=” —— a大于等于b吗?
? “<=” —— a小于等于b吗?
? “==” —— a等于b吗?
插入JavaScript的位置
JavaScript脚本可以放在网页的head里或者body部分,而且效果也不相同。
Body里的JavaScript
放在body部分的JavaScript脚本在网页读取到该语句的时候就会执行,例如:
<html>
<body>
<script type="text/JavaScript">
</script>
</head>
添加外部JavaScript脚本
也可以像添加外部CSS一样添加外部JavaScript脚本文件,其后缀通常为.js。例如:
<html>
<head>
<script src="scripts.js"></script>

js常用代码大全

js常用代码大全

js常⽤代码⼤全Javascript常⽤代码⼤全//打开模式对话框<body><script language=javascript>function doSelectUser(txtId){strFeatures="dialogWidth=500px;dialogHeight=360px;center=yes;middle=yes ;help=no;status=no;scroll=no";var url,strReturn;url="selUser.aspx";strReturn=window.showModalDialog(url,',strFeatures');} doSelectUser()</script></body>//返回模式对话框的值function okbtn_onclick() {var commstr='';window.returnValue=commstr;window.close() ;} okbtn_onclick()//全屏幕打开 IE 窗⼝var winWidth=screen.availWidth ;var winHeight=screen.availHeight-20;window.open("main.aspx","surveyWindow","toolbar=no,width="+ winWidth +",height="+ winHeight +",top=0,left=0,scrollbars=yes,resizable=yes,center:yes,statusbars=yes"); //脚本中中使⽤xmlfunction initialize() {var xmlDocvar xslDocxmlDoc = new ActiveXObject('Microsoft.XMLDOM')xmlDoc.async = false;xslDoc = new ActiveXObject('Microsoft.XMLDOM')xslDoc.async = false;xmlDoc.load("tree.xml")xslDoc.load("tree.xsl")folderTree.innerHTML = xmlDoc.documentElement.transformNode(xslDoc)}⼀、验证类1、数字验证内1.1 整数1.2 ⼤于0的整数(⽤于传来的ID的验证)1.3 负整数的验证1.4 整数不能⼤于iMax1.5 整数不能⼩于iMin2、时间类2.1 短时间,形如 (13:04:06)2.2 短⽇期,形如 (2003-12-05)2.3 长时间,形如 (2003-12-05 13:04:06)2.4 只有年和⽉。

JS语法大全

JS语法大全
62.addBehavior()是一种JS调用的外部函数文件其扩展名为.htc
63.window.focus()使当前的窗口在所有窗口之前.
64.blur()指失去焦点.与FOCUS()相反.
65.select()指元素为选中状态.
66.防止用户对文本框中输入文本:onfocus="this.blur()"
72.JS中指定当前打开窗口的父窗口:window.opener,支持opener.opener...的多重继续.
73.JS中的self指的是当前的窗口
74.JS中状态栏显示内容:window.status="内容"
75.JS中的top指的是框架集中最顶层的框架
76.JS中关闭当前的窗口:window.close();
29.得到元素的方法:document.getElementById()
30.设置表单中所有文本型的成员的值为空:
var form = window.document.forms[0]
for (var i = 0; i<form.elements.length;i++){
if (form.elements.type == "text"){
20.状态栏的设置:window.status="字符";
21.弹出提示信息:window.alert("字符");
22.弹出确认框:window.confirm();
23.弹出输入提示框:window.prompt();
24.指定当前显示链接的位置:window.location.href="/blog/URL"
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

转载js大全收藏事件源对象捕获释放event.srcElement.setCapture();event.srcElement.releaseCapture();事件按键event.keyCodeevent.shiftKeyevent.altKeyevent.ctrlKey事件返回值event.returnValue鼠标位置event.xevent.y窗体活动元素document.activeElement绑定事件document.captureEvents(Event.KEYDOWN);访问窗体元素document.all("txt").focus();document.all("txt").select();窗体命令document.execCommand窗体COOKIEdocument.cookie菜单事件document.oncontextmenu创建元素document.createElement("SPAN");根据鼠标获得元素:document.elementFromPoint(event.x,event.y).tagName=="TD document.elementFromPoint(event.x,event.y).appendChild(ms) 窗体图片document.images[索引]窗体事件绑定document.onmousedown=scrollwindow;元素document.窗体.elements[索引]对象绑定事件document.all.xxx.detachEvent(’onclick’,a);插件数目navigator.plugins取变量类型typeof($js_libpath) == "undefined"下拉框下拉框.options[索引]下拉框.options.length查找对象document.getElementsByName("r1");document.getElementById(id);定时alert(decodeURIComponent(encodeURIComponent("http://你好.com?as= hehe"))) encodeURIComponent对":"、"/"、";" 和"?"也编码<tr onmouseover="this.bgColor=’#f0f0f0’" onmouseout="this.bgColor=’#ffffff’">//各种尺寸timer=setInterval(’scrollwindow()’,delay);clearInterval(timer);UNCODE编码escape() ,unescape父对象obj.parentElement(dhtml)obj.parentNode(dom)交换表的行TableID.moveRow(2,1)替换CSSdocument.all.csss.href = "a.css";并排显示display:inline隐藏焦点hidefocus=true根据宽度换行style="word-break:break-all"自动刷新<meta HTTP-EQUIV="refresh" CONTENT="8;URL=">简单邮件<a href="mailto:aaa@?subject=ccc&body=xxxyyy">快速转到位置obj.scrollIntoView(true)锚<a name="first"><a href="#first">anchors</a>网页传递参数location.search();可编辑obj.contenteditable=true执行菜单命令obj.execCommand双字节字符/[^\x00-\xff]/汉字/[\u4e00-\u9fa5]/让英文字符串超出表格宽度自动换行word-wrap: break-word; word-break: break-all;透明背景<IFRAME src="1.htm" width=300 height=180 allowtransparency></iframe>获得style内容obj.style.cssTextHTML标签document.documentElement.innerHTML第一个style标签document.styleSheets[0]style标签里的第一个样式document.styleSheets[0].rules[0]防止点击空链接时,页面往往重置到页首端。

<a href="javascript:function()">word</a>上一网页源asp:request.servervariables("HTTP_REFERER")javascript:document.referrer释放内存CollectGarbage();禁止右键document.oncontextmenu = function() { return false;}禁止保存<noscript><iframe src="*.htm"></iframe></noscript>禁止选取<body oncontextmenu="return false" ondragstart="return false"onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false"onmouseup="document.selection.empty()>禁止粘贴<input type=text onpaste="return false">地址栏图标<link rel="Shortcut Icon" href="favicon.ico">favicon.ico 名字最好不变16*16的16色,放虚拟目录根目录下收藏栏图标<link rel="Bookmark" href="favicon.ico">查看源码<input type=button value=查看网页源代码onclick="window.location = ’view-source:’+ ’/’">关闭输入法<input style="ime-mode:disabled">自动全选<input type=text name=text1 value="123" onfocus="this.select()">ENTER键可以让光标移到下一个输入框<input onkeydown="if(event.keyCode==13)event.keyCode=9">文本框的默认值<input type=text value="123" onfocus="alert(this.defaultValue)">title换行obj.title = "123 sdfs "获得时间所代表的微秒var n1 = new Date("2004-10-10".replace(/-/g, "\/")).getTime()窗口是否关闭win.closedcheckbox扁平<input type=checkbox style="position: absolute; clip:rect(5px 15px 15px 5px)"><br>获取选中内容document.selection.createRange().duplicate().text自动完成功能<input type=text autocomplete=on>打开该功能<input type=text autocomplete=off>关闭该功能窗口最大化<body onload="window.resizeTo(window.screen.width - 4,window.screen.height-50);window.moveTo(-4,-4)">无关闭按钮IEwindow.open("aa.htm", "meizz", "fullscreen=7");统一编码/解码表格行指示s += "\r\n网页可见区域宽:"+ document.body.clientWidth;s += "\r\n网页可见区域高:"+ document.body.clientHeight;s += "\r\n网页可见区域高:"+ document.body.offsetWeight +" (包括边线的宽)";s += "\r\n网页可见区域高:"+ document.body.offsetHeight +" (包括边线的宽)";s += "\r\n网页正文全文宽:"+ document.body.scrollWidth;s += "\r\n网页正文全文高:"+ document.body.scrollHeight;s += "\r\n网页被卷去的高:"+ document.body.scrollTop;s += "\r\n网页被卷去的左:"+ document.body.scrollLeft;s += "\r\n网页正文部分上:"+ window.screenTop;s += "\r\n网页正文部分左:"+ window.screenLeft;s += "\r\n屏幕分辨率的高:"+ window.screen.height;s += "\r\n屏幕分辨率的宽:"+ window.screen.width;s += "\r\n屏幕可用工作区高度:"+ window.screen.availHeight;s += "\r\n屏幕可用工作区宽度:"+ window.screen.availWidth; event.srcElement.tagNameevent.srcElement.type//过滤数字<input type=text onkeypress="return event.keyCode>=48&&event.keyCode<=57||(this.value.indexOf(’.’)<0?event.keyCode==46:false )" onpaste="return !clipboardData.getData(’text’).match(/\D/)" ondragenter="return false">//特殊用途<input type=button value=导入收藏夹onclick="window.exte rnal.ImportExportFavorites(true,’http://localhost’);"><input type=button value=导出收藏夹onclick="window.external.ImportExportFavorites(false,’http://localhost’);"><input type=button value=整理收藏夹onclick="window.external.ShowBrowserUI(’OrganizeFavorites’, n ull)"><input type=button value=语言设置onclick="window.external.ShowBrowserUI(’LanguageDialog’, null)"><input type=button value=加入收藏夹onclick="window.external.AddFavorite(’/’, ’google’)"><input type=button value=加入到频道onclick="win dow.external.addChannel(’/’)"><input type=button value=加入到频道onclick="window.external.showBrowserUI(’PrivacySettings’,null)">//不缓存//正则匹配匹配中文字符的正则表达式:[\u4e00-\u9fa5]匹配双字节字符(包括汉字在内):[^\x00-\xff]匹配空行的正则表达式:\n[\s| ]*\r匹配HTML标记的正则表达式:/<(.*)>.*<\/\1>|<(.*) \/>/匹配首尾空格的正则表达式:(^\s*)|(\s*$)(像vbscript那样的trim函数)匹配Email地址的正则表达式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*匹配网址URL的正则表达式:http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?以下是例子:利用正则表达式限制网页表单里的文本框输入内容:用正则表达式限制只能输入中文:onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,’’)" onbeforepaste="clipboardData.setData(’text’,clipboardData.getData(’text’).replace(/[^\u4E00-\u9 FA5]/g,’’))"1.用正则表达式限制只能输入全角字符:onkeyup="value=value.replace(/[^\uFF00-\uFFFF]/g,’’)"onbeforepaste="clipb oardData.setData(’text’,clipboardData.getData(’text’).replace(/[^\uFF00-\uF FFF]/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,’’))" //消除图像工具栏<IMG SRC="mypicture.jpg" HEIGHT="100px" WIDTH="100px" GALLERYIMG="false">or<head><meta http-equiv="imagetoolbar" content="no"></head>//无提示关闭function Close(){var ua=erAgentvar ie=navigator.appName=="Microsoft Internet Explorer"?true:falseif(ie){var IEversion=parseFloat(ua.substring(ua.indexOf("MSIE ")+5,ua.indexOf(";",ua.indexOf("MSIE "))))if(IEversion< 5.5){var str = ’<object id=noTipClose classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">’str += ’<param name="Command" value="Close"></object>’;document.body.insertAdjacentHTML("beforeEnd", str);document.all.noTipClose.Click();}else{window.opener =null;window.close();}}else{window.close()}}//取得控件得绝对位置(1)<script language="javascript">function 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);rec[0] = t;rec[1] = l;return rec}</script>//获得控件的绝对位置(2)oRect = obj.getBoundingClientRect();oRect.leftoRect.//最小化,最大化,关闭<object id=min classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11"><param name="Command" value="Minimize"></object><object id=max classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11"><param name="Command" value="Maximize"></object><OBJECT id=close classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"><PARAM NAME="Command" value="Close"></OBJECT><input type=button value=最小化onclick=min.Click()><input type=button value=最大化onclick=max.Click()><input type=button value=关闭onclick=close.Click()>//光标停在文字最后//页面进入和退出的特效进入页面<meta http-equiv="Page-Enter" content="revealTrans(duration=x, transition=y)">推出页面<meta http-equiv="Page-Exit" content="revealTrans(duration=x, transition=y)">这个是页面被载入和调出时的一些特效。

相关文档
最新文档