JS代码大全收藏
Javascript弹窗代码大全(收集)

弹窗代码大全(收集)以下包括强制弹窗 24小时IP弹窗延时弹窗退弹等我们使用cookie来控制一下就可以了。
首先,将如下代码加入主页面html的<head>区:<script>function openwin(){window.open(”page.html”,”",”width=200,height=200″)}function get_cookie(name){var search = name + “=”var returnvalue = “”;if (documents.cookie.length > 0) {offset = documents.cookie.indexof(search)if (offset != -1) {offset += search.lengthend = documents.cookie.indexof(”;”, offset);if (end == -1)end = documents.cookie.length;returnvalue=”/unescape(documents.cookie.substring(offset,end))”}}return returnvalue;}function loadpopup(){if (get_cookie(’popped’)==”){openwin()documents.cookie=”popped=yes”}}</script>然后,用<body onload=”loadpopup()”>(注意不是openwin而是loadpop啊!)替换主页面中原有的<body>这一句即可。
你可以试着刷新一下这个页面或重新进入该页面,窗口再也不会弹出了。
真正的pop-only-once!写到这里弹出窗口的制作和应用技巧基本上算是完成了,俺也累坏了,一口气说了这么多,希望对正在制作网页的朋友有所帮助俺就非常欣慰了。
JS100行代码实现贪吃蛇,快写给你的女朋友

JS100⾏代码实现贪吃蛇,快写给你的⼥朋友<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>贪吃蛇</title><style>*{margin: 0;padding: 0;}#root{width: 100%;font-size: 0;}.block{display: inline-block;}</style></head><body><div id="root"></div><script>const BLOCK_LENGTH = 30; //⽅格边长const BLOCK_COLOR = "white"; //⽅格颜⾊const FOOD_COLOR = "salmon"; //⾷物颜⾊const HEAD_COLOR = "orchid"; //头部颜⾊const BODY_COLOR = "plum"; //⾝体颜⾊let js = 0; //定时器IDlet w_size = Math.floor((window.screen.width || 450) / BLOCK_LENGTH), //横向⽅格数量h_size = Math.floor((document.documentElement.clientHeight || 450) / BLOCK_LENGTH); //纵向⽅格数量//⽣成地图 startif(true){let map = "";for(let i = 0, len = w_size * h_size; i < len; ++i){map += `<div class='block' style='width:${BLOCK_LENGTH}px;height:${BLOCK_LENGTH}px;background-color:${BLOCK_COLOR};'></div>`; }document.getElementById('root').innerHTML = map;}//⽣成地图 endlet snake_list = [0]; //蛇⾝let snake_length = 1; //蛇⾝长度let block_list = document.getElementsByClassName('block'); //⽅格列表function creat_food(){ //⽣成⾷物let sub = 0;if(snake_list.length / (w_size * h_size) < 0.75){sub = Math.floor(Math.random()*(w_size*h_size));while(block_list[sub].style.backgroundColor != BLOCK_COLOR){sub = Math.floor(Math.random()*(w_size*h_size));}}else{let block_arr = [];for(let i = 0, len = w_size * h_size; i < len; ++i){if(block_list[i].style.backgroundColor == BLOCK_COLOR){block_arr.push(i);}}sub = block_arr[Math.floor(Math.random()*(block_arr.length))];}block_list[sub].style.backgroundColor = FOOD_COLOR;}let dir = 4; //移动⽅向(上:1下:2左:3右:4)function move(){ //移动let handle = function(next){let max = next > snake_list[snake_length - 1] ? next : snake_list[snake_length - 1];if(block_list[next] == undefined ||block_list[next].style.backgroundColor == BODY_COLOR ||(Math.abs(next - snake_list[snake_length - 1]) == 1 &&max % w_size == 0)){clearInterval(js);alert("得分:" + snake_length);location.reload();}else if(block_list[next].style.backgroundColor == FOOD_COLOR){block_list[snake_list[snake_length - 1]].style.backgroundColor = BODY_COLOR;snake_list.push(next);++snake_length;block_list[next].style.backgroundColor = HEAD_COLOR;creat_food();}else{block_list[snake_list[snake_length - 1]].style.backgroundColor = BODY_COLOR;block_list[snake_list[0]].style.backgroundColor = BLOCK_COLOR;snake_list.shift();snake_list.push(next);block_list[snake_list[snake_length - 1]].style.backgroundColor = HEAD_COLOR;}};switch(dir){case 1:handle(snake_list[snake_length - 1] - w_size);break;case 2:handle(snake_list[snake_length - 1] + w_size);break;case 3:handle(snake_list[snake_length - 1] - 1);break;case 4:handle(snake_list[snake_length - 1] + 1);break;default:;}}document.onkeypress = function(e){let theEvent = e || window.event;let code = theEvent.keyCode || theEvent.which || theEvent.charCode;switch(code){case 38: case 119:(dir == 1 || dir == 2) ? void 0 : dir = 1;break;case 37: case 97:(dir == 3 || dir == 4) ? void 0 : dir = 3;break;case 40: case 115:(dir == 1 || dir == 2) ? void 0 : dir = 2;break;case 39: case 100:(dir == 3 || dir == 4) ? void 0 : dir = 4;break;default:;}};block_list[snake_list[0]].style.backgroundColor = HEAD_COLOR;creat_food();js = setInterval(move, 300);</script></body></html>代码易读不⽤解释,只提⼀个事,蛇移动的时候,没必要每个部位都动,只处理头尾就可以了,这个应该也是显⽽易见的。
常用的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>。
最新40个经典网页代码

40个经典网页代码1231. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标4右键5<table border oncontextmenu=return(false)><td>no</table> 可用于6Table782. <body onselectstart="return false"> 取消选取、防止复制9103. onpaste="return false" 不准粘贴11124. oncopy="return false;" oncut="return false;" 防止复制13145. <link rel="Shortcut Icon" href="favicon.ico"> IE地址栏前换成自15己的图标16176. <link rel="Bookmark" href="favicon.ico"> 可以在收藏夹中显示出18你的图标19207. <input style="ime-mode:disabled"> 关闭输入法21228. 永远都会带着框架23<s cript language="Javas cript"><!--24if (window == top)top.location.href =25"frames.htm"; //frames.htm为框架网页26// --></s cript>27289. 防止被人frame29<s cript LANGUAGE=JAVAs cript><!--30if (top.location != self.location)top.location=self.location;31// --></s cript>323310. 网页将不能被另存为34<nos cript><iframe src=*.html></iframe></nos cript>353611. <input type=button value=查看网页源代码37onclick="window.location = "view-source:"+38"";">394012.删除时确认41<a href="javas cript:if(confirm("确实要删除吗?"))42location="boos.asp?&areyou=删除&page=1"">删除</a>434413. 取得控件的绝对位置45//Javas cript46<s cript language="Javas cript">47function getIE(e){48var t=e.offsetTop;49var l=e.offsetLeft;50while(e=e.offsetParent){51t+=e.offsetTop;52l+=e.offsetLeft;53}54alert("top="+t+"/nleft="+l);55}56</s cript>57//VBs cript58<s cript language="VBs cript"><!--59function getIE()60dim t,l,a,b61set a=document.all.img162t=document.all.img1.offsetTop63l=document.all.img1.offsetLeft64while a.tagName<>"BODY"65set a = a.offsetParent66t=t+a.offsetTop67l=l+a.offsetLeft68wend69msgbox "top="&t&chr(13)&"left="&l,64,"得到控件的位置"70end function71--></s cript>727314. 光标是停在文本框文字的最后74<s cript language="javas cript">75function cc()76{77var e = event.srcElement;78var r =e.createTextRange();79r.moveStart("character",e.value.length);80r.collapse(true);81r.select();82}83</s cript>84<input type=text name=text1 value="123" onfocus="cc()">858615. 判断上一页的来源87javas cript:88document.referrer899016. 最小化、最大化、关闭窗口91<object id=hh192classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">93<param name="Command" value="Minimize"></object>94<object id=hh2 95classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">96<param name="Command" value="Maximize"></object>97<OBJECT id=hh3 98classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">99<PARAM NAME="Command" VALUE="Close"></OBJECT>100<input type=button value=最小化 onclick=hh1.Click()>101<input type=button value=最大化 onclick=hh2.Click()>102<input type=button value=关闭 onclick=hh3.Click()>103本例适用于IE10410517.屏蔽功能键Shift,Alt,Ctrl106<s cript>107function look(){108if(event.shiftKey)109alert("禁止按Shift键!"); //可以换成ALT CTRL110}111document.onkeydown=look;112</s cript>11311418. 网页不会被缓存115<META HTTP-EQUIV="pragma" CONTENT="no-cache">116<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, 117must-revalidate">118<META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT"> 119或者<META HTTP-EQUIV="expires" CONTENT="0">12012119.怎样让表单没有凹凸感?122<input type=text style="border:1 solid #000000">123或124<input type=text style="border-left:none;125border-right:none; border-top:none; border-bottom:1261 solid #000000"></textarea>12712820.<div><span>&<layer>的区别?129<div>(division)用来定义大段的页面元素,会产生转行130<span>用来定义同一行内的元素,跟<div>的唯一区别是不产生转行131<layer>是ns的标记,ie不支持,相当于<div>13213321.让弹出窗口总是在最上面:134<body onblur="this.focus();">13513622.不要滚动条?137让竖条没有:138<body style="overflow:scroll;overflow-y:hidden">139</body>140让横条没有:141<body style="overflow:scroll;overflow-x:hidden">142</body>143两个都去掉?更简单了144<body scroll="no">145</body>14614723.怎样去掉图片链接点击后,图片周围的虚线?148<a href="#" onFocus="this.blur()">149<img src="logo.jpg" border=0></a>15015124.电子邮件处理提交表单152<form name="form1" method="post"153action="mailt****@***.com" enctype="text/plain">154<input type=submit>155</form>15615725.在打开的子窗口刷新父窗口的代码里如何写?158window.opener.location.reload()15916026.如何设定打开页面的大小161<body onload="top.resizeTo(300,200);">162打开页面的位置<body onload="top.moveBy(300,200);">16316427.在页面中如何加入不是满铺的背景图片,拉动页面时背景图不动165<STYLE>166body167{background-image:url(logo.gif); background-repeat:no-repeat; 168background-position:center;background-attachment: fixed}169</STYLE>17017128. 检查一段字符串是否全由数字组成172<s cript language="Javas cript"><!--173function checkNum(str){return str.match(//D/)==null}174alert(checkNum("1232142141"))175alert(checkNum("123214214a1"))176// --></s cript>17717829. 获得一个窗口的大小179document.body.clientWidth; document.body.clientHeight18018130. 怎么判断是否是字符182if (/[^/x00-/xff]/g.test(s)) alert("含有汉字");183else alert("全是字符");18418531.TEXTAREA自适应文字行数的多少186<textarea rows=1 name=s1 cols=27187onpropertychange="this.style.posHeight=this.scrollHeight"> 188</textarea>18919019132. 日期减去天数等于第二个日期192<s cript language=Javas cript>193function cc(dd,dadd)194{195//可以加上错误处理196var a = new Date(dd)197a = a.valueOf()198a = a - dadd * 24 * 60 * 60 * 1000199a = new Date(a)200alert(a.getFullYear() + "年" + (a.getMonth() + 1)201+ "月" + a.getDate() + "日")202}203cc("12/23/2002",2)204</s cript>20520633. 选择了哪一个Radio207<HTML><s cript language="vbs cript">208function checkme()209for each ob in radio1210if ob.checked then window.alert ob.value211next212end function213</s cript><BODY>214<INPUT name="radio1" type="radio" value="style" checked>Style 215<INPUT name="radio1" type="radio" value="barcode">Barcode 216<INPUT type="button" value="check" onclick="checkme()">217</BODY></HTML>21821934.脚本永不出错220<s cript LANGUAGE="Javas cript">221<!-- Hide222function killErrors() {223return true;224}225window.onerror = killErrors;226// -->227</s cript>22822935.ENTER键可以让光标移到下一个输入框230<input onkeydown="if(event.keyCode==13)event.keyCode=9"> 23123236. 检测某个网站的链接速度:233把如下代码加入<body>区域中:234<s cript language=Javas cript>235tim=1236setInterval("tim++",100)237b=1238var autourl=new Array()239autourl[1]=""240autourl[2]=""241autourl[3]=""242autourl[4]=""243autourl[5]=""244function butt(){245document.write("<form name=autof>")246for(var i=1;i<autourl.length;i++)247document.write("<input type=text name=txt"+i+" size=10 248value=测试中……> =》<input type=text249name=url"+i+" size=40> =》<input type=button value=GO 250onclick=window.open(this.form.url"+i+".value)><br>") 251document.write("<input type=submit value=刷新></form>") 252}253butt()254function auto(url){255document.forms[0]["url"+b].value=url256if(tim>200)257{document.forms[0]["txt"+b].value="链接超时"}258else259{document.forms[0]["txt"+b].value="时间"+tim/10+"秒"}260b++261}262function run(){for(var i=1;i<autourl.length;i++)263document.write("<img src=http://"+autourl+"/"+Math.random()+" 264width=1 height=1265onerror=auto("http://";+autourl+"")>")}266run()</s cript>26726837. 各种样式的光标269auto :标准光标270default :标准箭头271hand :手形光标272wait :等待光标273text :I形光标274vertical-text :水平I形光标275no-drop :不可拖动光标276not-allowed :无效光标277help :?帮助光标278all-scroll :三角方向标279move :移动标280crosshair :十字标281e-resize282n-resize283nw-resize284w-resize285s-resize286se-resize287sw-resize28828938.页面进入和退出的特效290进入页面<meta http-equiv="Page-Enter"291content="revealTrans(duration=x, transition=y)">292推出页面<meta http-equiv="Page-Exit"293content="revealTrans(duration=x, transition=y)">294这个是页面被载入和调出时的一些特效。
100句javascript一句话代码(简短常用代码集合,js开发必备的小程序集)

32.单选按钮组(单选按钮的名称必须相同):取单选按钮组的长度document.forms[0].groupName.length
70.添加到收藏夹:external.AddFavorite(””,”jaskdlf”);
71.JS中遇到脚本错误时不做任何操作:window.onerror = doNothing; 指定错误句柄的语法为:window.onerror = handleError;
58.innerTEXT的值和上面的一样,只不过不会把< em >这种标记显示出来.
59.contentEditable可设置元素是否可被修改,isContentEditable返回是否可修改的状态.
60.isDisabled判断是否为禁止状态.disabled设置禁止状态
61.length取得长度,返回整型数值
67.取出该元素在页面中出现的数量:document.all.tags(”div(或其它HTML标记符)”).length
68.JS中分为两种窗体输出:模态和非模态.window.showModaldialog(),window.showModeless()
69.状态栏文字的设置:window.status=’文字’,默认的状态栏文字设置:window.defaultStatus = ‘文字.’;
52.JS的内建对象有:Array,Boolean,Date,Error,EvalError,Function,Math,Number,Object,RangeError,ReferenceError,RegExp,String,SyntaxError,TypeError,URIError
JS跳转页面参考代码大全

JS跳转页面参考代码第一种:<script language="javascript" type="text/javascript"> window.location.href="login.jsp?backurl="+window.location.href; </script>第二种:<script language="javascript">alert("返回");window.history.back(-1);</script>第三种:<script language="javascript">window.navigate("top.jsp");</script>第四种:<script language="JavaScript">self.location=’top.htm’;</script>第五种:<script language="javascript">alert("非法访问!");top.location=’xx.jsp’;</script>=====javascript中弹出选择框跳转到其他页面=====<script language="javascript"><!--function logout()...{if (confirm("你确定要注销身份吗?是-选择确定,否-选择取消"))...{ window.location.href="logout.asp?act=logout"}}--></script>=====javascript中弹出提示框跳转到其他页面=====<script language="javascript"><!--function logout()...{alert("你确定要注销身份吗?");window.location.href="logout.asp?act=logout"}--></script>=================================按钮式:<INPUT name="pclog" type="button" value="GO"onClick="location.href='/'">链接式:<a href="javascript:history.go(-1)">返回上一步</a><a href="<%=Request.ServerVariables("HTTP_REFERER")%>">返回上一步</a>直接跳转式:<script>window.location.href='/';</script>开新窗口:<a href="javascript:"onClick="window.open(/','','height=500,width=611,scrollbar s=yes,status=yes')">杭州威士顿网络科技有限公司</a>。
比较有意思的代码

比较有意思的代码1. 打印彩虹:使用不同颜色的 ASCII 码打印出一道彩虹。
```for(let i = 0; i <= 7; i++) {console.log(`\x1b[38;5;${i}m${'*'.repeat(i * 4)}`);}```2. 绘制 ASCII 图形:使用 ASCII 码绘制简单的图形,例如心形或笑脸。
```function drawHeart() {console.log('❤️');}function drawSmiley() {console.log(' ');}drawHeart();drawSmiley();```3. 生成随机诗句:使用 JavaScript 生成随机的诗句。
```function generateRandomPoem() {let poem = [];let words = ['青山', '绿水', '蓝天', '白云', '明月', '清风', '桃花', '春雨', '秋霜', '冬雪'];for(let i = 0; i < 4; i++) {let randomWord = words[Math.floor(Math.random() * words.length)];poem.push(randomWord);}poem.push('美丽');poem.push('人间');return poem.join(' ');}console.log(generateRandomPoem());```4. 生成验证码:使用 JavaScript 生成随机的验证码。
```function generateRandomCode() {let code = '';let characters = '0123456789abcdefghijklmnopqrstuvwxyz';for(let i = 0; i < 6; i++) {let randomCharacter = characters[Math.floor(Math.random() * characters.length)];code += randomCharacter;}return code;}console.log(generateRandomCode());```这些代码都比较有趣,可以让你体验到编程的乐趣。
JS代码大全

JS代码⼤全1. 将彻底屏蔽⿏标右键oncontextmenu="window.event.returnvalue=false"<table border oncontextmenu=return(false)><td>no</table>可⽤于Table2. 取消选取、防⽌复制<body onselectstart="return false">3. 不准粘贴onpaste="return false"4. 防⽌复制oncopy="return false;" oncut="return false;"5. IE地址栏前换成⾃⼰的图标<link rel="Shortcut Icon" href="favicon.ico">6. 可以在收藏夹中显⽰出你的图标<link rel="Bookmark" href="favicon.ico">7. 关闭输⼊法<input style="ime-mode:-Disabled">8. 永远都会带着框架<script language="javascript"><!--if (window == top)top.location.href = "frames.htm"; //frames.htm为框架⽹页// --></script>9. 防⽌被⼈frame<SCRIPT LANGUAGE=javascript><!--if (top.location != self.location)top.location=self.location;// --></SCRIPT>10. ⽹页将不能被另存为<noscript><iframe src=*.html></iframe></noscript>11. 查看⽹页源代码<input type=button value=查看⽹页源代码onclick="window.location = `view-source:`+ /`";>12.删除时确认<a href=`javascript:if(confirm("确实要删除吗?"location="boos.asp?&areyou=删除&page=1"`>删除</a>13. 取得控件的绝对位置//javascript<script language="javascript">function getIE(E){var t=e.offsetTop;var l=e.offsetLeft;while(e=e.offsetParent){t+=e.offsetTop;l+=e.offsetLeft;}alert("top="+t+"/nleft="+l);}</script>//VBScript<script language="VBScript"><!--function getIE()dim t,l,a,bset a=document.all.img1t=document.all.img1.offsetTopl=document.all.img1.offsetLeftwhile a.tagName<>"BODY"set a = a.offsetParentt=t+a.offsetTopl=l+a.offsetLeftwendmsgbox "top="&t&chr(13)&"left="&l,64,"得到控件的位置"end function--></script>14. 光标是停在⽂本框⽂字的最后<script language="javascript">function cc(){var e = event.srcElement;var r =e.createTextRange();r.moveStart(`character`,e.value.length);r.collapse(true);r.select();}</script><input type=text name=text1 value="123" onfocus="cc()">15. 判断上⼀页的来源javascript:document.referrer16. 最⼩化、最⼤化、关闭窗⼝<object id=hh1 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11"><param name="Command" value="Minimize"></object><object id=hh2 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11"><param name="Command" value="Maximize"></object><OBJECT id=hh3 classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"><PARAM NAME="Command" value="Close"></OBJECT><input type=button value=最⼩化onclick=hh1.Click()><input type=button value=最⼤化onclick=hh2.Click()><input type=button value=关闭onclick=hh3.Click()>本例适⽤于IE17.屏蔽功能键Shift,Alt,Ctrl<script>function look(){if(event.shiftKey)alert("禁⽌按Shift键!"; //可以换成ALT CTRL}document.onkeydown=look;</script>18. ⽹页不会被缓存<META HTTP-EQUIV="pragma" CONTENT="no-cache"><META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate"><META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">或者<META HTTP-EQUIV="expires" CONTENT="0">19.怎样让表单没有凹凸感?<input type=text style="border:1 solid #000000">或<input type=text style="border-left:none; border-right:none; border-top:none; border-bottom: 1 solid #000000"></textarea>20.<div><span>&<layer>的区别?<div>(division)⽤来定义⼤段的页⾯元素,会产⽣转⾏<span>⽤来定义同⼀⾏内的元素,跟<div>的唯⼀区别是不产⽣转⾏<layer>是ns的标记,ie不⽀持,相当于<div>21.让弹出窗⼝总是在最上⾯:<body onblur="this.focus();">22.不要滚动条?让竖条没有:<body style=`overflow:-Scroll;overflow-y:hidden`></body>让横条没有:<body style=`overflow:-Scroll;overflow-x:hidden`></body>两个都去掉?更简单了<body scroll="no"></body>23.怎样去掉图⽚链接点击后,图⽚周围的虚线?<a href="#" onFocus="this.blur()"><img src="logo.jpg" border=0></a>24.电⼦邮件处理提交表单<form name="form1" method="post" action="mailto***@***.com" enctype="text/plain"><input type=submit></form>25.在打开的⼦窗⼝刷新⽗窗⼝的代码⾥如何写?window.opener.location.reload()26.如何设定打开页⾯的⼤⼩<body onload="top.resizeTo(300,200);">打开页⾯的位置<body onload="top.moveBy(300,200);">27.在页⾯中如何加⼊不是满铺的背景图⽚,拉动页⾯时背景图不动<style>body{background-image:url(logo.gif); background-repeat:no-repeat;background-position:center;background-attachment: fixed}</style>28. 检查⼀段字符串是否全由数字组成<script language="javascript"><!--function checkNum(str){return str.match(//D/)==null}alert(checkNum("1232142141"alert(checkNum("123214214a1"// --></script>29. 获得⼀个窗⼝的⼤⼩document.body.clientWidth;document.body.clientHeight30. 怎么判断是否是字符if (/[^/x00-/xff]/g.test(s)) alert("含有汉字";else alert("全是字符";31.TEXTAREA⾃适应⽂字⾏数的多少<textarea rows=1 name=s1 cols=27 onpropertychange="this.style.posHeight=this.scrollHeight"> </textarea>32. ⽇期减去天数等于第⼆个⽇期<script language=javascript>function cc(dd,dadd){//可以加上错误处理var a = new Date(dd)a = a.valueOf()a = a - dadd * 24 * 60 * 60 * 1000a = new Date(A)alert(a.getFullYear() + "年" + (a.getMonth() + 1) + "⽉" + a.getDate() + "⽇"}cc("12/23/2002",2)</script>33. 选择了哪⼀个Radio<HTML><script language="vbscript">function checkme()for each ob in radio1if ob.checked then window.alert ob.valuenextend function</script><BODY><INPUT name="radio1" type="radio" value="style" checked>style<INPUT name="radio1" type="radio" value="barcode">Barcode<INPUT type="button" value="check" onclick="checkme()"></BODY></HTML>34.脚本永不出错<SCRIPT LANGUAGE="javascript"><!-- Hidefunction killErrors() {return true;}window.onerror = killErrors;// --></SCRIPT>35.ENTER键可以让光标移到下⼀个输⼊框<input onkeydown="if(event.keyCode==13)event.keyCode=9">36. 检测某个⽹站的链接速度:把如下代码加⼊<body>区域中:<script language=javascript>tim=1setInterval("tim++",100)b=1var autourl=new Array()autourl[1]="/";autourl[2]=""autourl[3]="/";autourl[4]="/";autourl[5]="/";function butt(){document.write("<form name=autof>"for(var i=1;i<autourl.length;i++)document.write("<input type=text name=txt"+i+" size=10 value=测试中……> =》<input type=text name=url"+i+" size=40> =》<input type=button value=GOonclick=window.open(this.form.url"+i+".value)><br>"document.write("<input type=submit value=刷新></form>"}butt()function auto(url){document.forms[0]["url"+b].value=urlif(tim>200){document.forms[0]["txt"+b].value="链接超时"}else{document.forms[0]["txt"+b].value="时间"+tim/10+"秒"}b++}function run(){for(var i=1;i<autourl.length;i++)document.write("<imgsrc=http://"+autourl+"/"+Math.random()+" width=1 height=1onerror=auto(http://";+autourl+"`)>"}run()</script>37. 各种样式的光标auto :标准光标default :标准箭头hand :⼿形光标wait :等待光标text :I形光标vertical-text :⽔平I形光标no-drop :不可拖动光标not-allowed :⽆效光标help :?帮助光标all-scroll :三⾓⽅向标move :移动标crosshair :⼗字标e-resizen-resizenw-resizew-resizes-resizese-resizesw-resize38.页⾯进⼊和退出的特效进⼊页⾯<meta http-equiv="Page-Enter" content="revealTrans(duration=x, transition=y)">推出页⾯<meta http-equiv="Page-Exit" content="revealTrans(duration=x, transition=y)">这个是页⾯被载⼊和调出时的⼀些特效。
常用JS代码大全

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

javascript弹出窗⼝代码⼤全如何利⽤⽹页弹出各种形式的窗⼝,我想⼤家⼤多都是知道些的,但那种多种多样的弹出式窗⼝是怎么搞出来的,今天找了⼀篇好⽂学习了: 1.弹启⼀个全屏窗⼝<html><body onload="window.open('','example01','fullscreen');">;<b></b></body></html> 2.弹启⼀个被F11化后的窗⼝<html><body onload="window.open(''','example02','channelmode');">;<b></b></body></html> 3.弹启⼀个带有收藏链接⼯具栏的窗⼝<html><body onload="window.open('','example03','width=400,height=300,directories');"><b></b></body></html> 4.⽹页对话框<html><SCRIPT LANGUAGE="javascript"><!--showModalDialog(','example04','dialogWidth:400px;dialogHeight:300px;dialogLeft:200px;dialogTop:150px;center:yes;help:yes;resizable:yes;status:yes')//--></SCRIPT><b></b></body></html><html><SCRIPT LANGUAGE="javascript"><!--showModelessDialog(','example05','dialogWidth:400px;dialogHeight:300px;dialogLeft:200px;dialogTop:150px;center:yes;help:yes;resizable:yes;status:yes')//--></SCRIPT><b></b></body></html> showModalDialog()或是showModelessDialog() 来调⽤⽹页对话框,⾄于showModalDialog()与showModelessDialog()的区别,在于showModalDialog()打开的窗⼝(简称模式窗⼝),置在⽗窗⼝上,必须关闭才能访问⽗窗⼝(建议尽量少⽤,以免招⼈反感);showModelessDialog()dialogHeight: iHeight 设置对话框窗⼝的⾼度。
javascript常用代码大全-网页设计HTMLCSS

javasc ript常用代码大全-网页设计,HTM LCSS//打开模式对话框fun ction dose lectu ser(t xtid){ s trfea tures="dia logwi dth=500px;dialo gheig ht=360px;c enter=yes;middl e=yes ;hel p=n o;statu s=no;scrol l=no";v ar ur l,str retur n; ur l="se luser.aspx";s trret urn=w indow.show modal dialo g(url,,str featu res);}//返回模式对话框的值funct ion o kbtn_oncli ck(){v ar co mmstr=; windo w.ret urnva lue=c ommst r; wi ndow.close() ;}全屏幕打开ie 窗口var winw idth=scree n.ava ilwid th ;varwinhe ight=scree n.ava ilhei ght-20;w indow.open("mai n.asp x","s urvey windo w","t oolba r=no,width="+ w inwid th +",hei ght=" + win heigh t +",top=0,lef t=0,s croll bars=yes,r esiza ble=y es,ce nter:yes,s tatus bars=yes"); br eak //脚本中中使用xm lfu nctio n ini tiali ze(){var x mldocv ar xs ldoc xmld oc =new a ctive xobje ct(mi croso ft.xm ldom)x mldoc.asyn c = f alse;xsl doc = newactiv exobj ect(m icros oft.x mldom)xsldo c.asy nc =false;xml doc.l oad("tree.xml")x sldoc.load("tre e.xsl")fol dertr ee.in nerht ml =xmldo c.doc ument eleme nt.tr ansfo rmnod e(xsl doc)}一、验证类1、数字验证内1.1 整数1.2 大于0的整数(用于传来的id的验证) 1.3负整数的验证 1.4整数不能大于imax1.5 整数不能小于i min 2、时间类2.1 短时间,形如(13:04:06)2.2 短日期,形如(2003-12-05) 2.3长时间,形如 (2003-12-05 13:04:06) 2.4只有年和月。
javascript实用代码大全

javascript实⽤代码⼤全//取得控件得绝对位置(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()>//光标停在⽂字最后<script language="javascript">function cc(){var e = event.srcElement;var r =e.createTextRange();r.moveStart('character',e.value.length);r.collapse(true);r.select();}</script><input type=text name=text1 value="123" onfocus="cc()">//页⾯进⼊和退出的特效进⼊页⾯<meta http-equiv="Page-Enter" content="revealTrans(duration=x, transition=y)">推出页⾯<meta http-equiv="Page-Exit" content="revealTrans(duration=x, transition=y)">这个是页⾯被载⼊和调出时的⼀些特效。
js宏编程实例100例

js宏编程实例100例JS宏编程的实例是指通过JS语言编写的一些宏命令,可以实现复杂的操作并提高编程效率。
以下是100个JS宏编程实例。
1. 批量添加/删除/修改元素的属性2. 对多个元素同时进行样式修改3. 多维数组的排序、搜索、插入等操作4. 实现异步请求的队列管理5. 复制文本到剪贴板6. 防抖和节流7. 实现京东/淘宝商品发布的表单验证8. 获取URL参数并解析成对象9. 实现Canvas绘画动画效果10. 实现拖拽并改变元素位置11. 辅助Chrome插件自动化操作12. 实现input表单自动补全13. 分页器实现不同类型元素之间的切换14. 实现无限下拉加载15. 通过JS控制音视频播放器16. 实现网页定时跳转功能17. 实现留言板评论的增删改查操作18. 实现jQuery的$符号19. 实现一个树形结构的列表20. 实现一个拥有多个tab选项卡的导航菜单21. 实现一个轮播图22. 实现一个倒计时器23. 实现一个弹幕效果的网页24. 实现一个带编辑器的富文本输入框25. 实现一个可拖拽的利用ajax方式拖拽添加节点树形目录26. 实现一个基于图片的验证码27. 实现一个滑动验证的拖动验证码28. 实现一个可自动排版的相册页面29. 实现一个瀑布流布局的页面30. 实现一个网站访问来源分析的系统31. 实现一个短视频分享的层叠样式单元组件32. 实现一个轮廓定位的图像场景检测模块33. 实现一个文本模板的实时生成模块34. 实现一个参数修改复制链接功能35. 实现一个序列化表单并将其提交至服务器的模块36. 实现一个免费的在线聊天室37. 实现一个实时更新并展示不同网页的当前位置的工具38. 实现一个响应式布局39. 实现一个智能问答机器人40. 实现一个响应式导航栏41. 实现一个抽奖活动42. 实现一个分类筛选器43. 实现一个验证码图片生成器44. 实现一个网页实时可视化编辑器45. 实现一个基于投票的问卷调查问答库46. 实现一个移动端的二维码扫描器47. 实现一个基于地图的实时追踪系统48. 实现一个基于图像处理的ABC自动拼图助手49. 实现一个基于cbow算法的中英文分词器50. 实现一个协作文档编辑器51. 实现一个上传文件的插件52. 实现一个快速生成随机数据的插件53. 实现一个表单提交功能54. 实现一个日期选择器55. 实现一个本地缓存读写操作的插件56. 实现一个多语言切换的插件57. 实现一个用户登录/注册/找密码的插件58. 实现一个地图定位插件59. 实现一个分页插件60. 实现一个国际化插件61. 实现一个手势插件62. 实现一个内容高亮插件63. 实现一个实现图片懒加载的插件64. 实现一个事件日历插件65. 实现一个图表插件66. 实现一个博客日志插件67. 实现一个RSS订阅插件68. 实现一个天气预报插件69. 实现一个时钟计时器插件70. 实现一个音频播放器插件71. 实现一个视频播放器插件72. 实现一个图片放大镜插件73. 实现一个CSS压缩、合并并精简的插件74. 实现一个JS代码压缩、合并并精简的插件75. 实现一个字数统计插件76. 实现一个文本截断插件77. 实现一个文本滚动插件78. 实现一个搜索框自动完成插件79. 实现一个日历日期选择器插件80. 实现一个自定义弹出框插件81. 实现一个图像画廊插件82. 实现一个水印插件83. 实现一个自定义过滤器插件84. 实现一个全屏幕滚动插件85. 实现一个分屏滚动插件86. 实现一个拖拽文件上传插件87. 实现一个适用于移动端的表单插件88. 实现一个基于WebRTC的音视频聊天插件89. 实现一个基于PHPPowerPoint的电子讲义制作插件90. 实现一个基于WebGL的3D场景展示插件91. 基于CSS3实现的特效插件92. 实现一个工程/应用开发框架93. 实现一个前端性能分析插件94. 实现一个可视化组件库95. 实现一个路由管理插件96. 实现一个模型-视图-控制器(MVC)开发模式的应用框架97. 实现一个自定义模块模式的可扩展应用框架98. 实现一个测试管理/输出/断言库99. 实现一个集群管理框架100. 实现一个基于Node.js的全栈开发框架这些实例在JS宏编程中都很常见,可以提高编程效率和代码质量,也能够丰富开发者的编程技巧和经验。
5个有趣的js代码

5个有趣的js代码很多⼈认为编程语⾔只是⽤于⼯作,没有什么乐趣,其实,只要我们发挥奇思妙想,再死板的东西也有有趣的⼀⾯。
这篇⽂章告诉⼤家:使⽤JavaScript,可以做很多很多有趣的事情。
以下代码拷贝到地址栏回车即可运⾏,赶紧试试吧。
1. ⽹页射击游戏这个游戏可以在任何⽹页⾥⾯玩,把下⾯代码粘贴到地址栏回车,按空格键进⾏射击,W键可前进,A、D键或者⽅向键可改变射击⽅向。
javascript:var%20s%20=%20document.createElement('script');s.type='text/javascript';document.body.appendChild(s);s.src='';void(0);2. 让图⽚飞起来只要把下⾯的代码贴到浏览器的地址栏⾥然后按Enter键,当前⽹页的所有图⽚都将动起来。
javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; var DI=document.getElementsByTagName("img"); DIL=DI.length; function A(){for(i=0; i<DIL; i++){DIS=DI[ i ].style; DIS.position='absolute';DIS.left=Math.sin(R*x1+i*x2+x3)*x4+x5+"px"; DIS.top=Math.cos(R*y1+i*y2+y3)*y4+y5+"px"}R++}tag=setInterval('A()',5);document.onmousedown=function(){clearInterval(tag);for(i=0; i<DIL; i++){DI[i].style.position="static";}}; void(0)3. 让⽹页可编辑此JavaScript代码,可以让你实时修改任何的⽹页,在Firefox中,你甚⾄可以把修改的⽹页保存到起来,对于⽹页设计者来说,这个功能可以辅助完善页⾯效果。
(完整版)前端学习代码大全

left
左
表单部分
right
右
form
表单<form></form>,块元素
center
居中
action
表单提交的地址
段落部分
method
表单提交的方式
p
段落<p></p>,块元素
name
名称
blockquote
缩排、缩进
input
文本框<input/>
function
函数,对象
setInterval
启动定时器
clearInterval
关闭定时器
current
当前的
find
获得当前元素集合中每个元素的后代
onclick
鼠标点击触发事件
onmouseover
鼠标移动到元素上触发事件
onmousedown
鼠标在元素上按下时触发的事件
onmouseout
cursor:pointer;
光标变小手
*
通配符选择器例:*{color:red;}
list-style
列表
!important
提权
text-align
文本的水平对齐方式
链接部分
a
行内元素,链接<a></a>
JQ
href
超文本引用
hide
隐藏
target=”_blank”
新窗口打开
show
显示
link
背景颜色
ul
非排序列表
background-image
js表单验证代码大全

关键字:js验证表单大全,用JS控制表单提交 ,javascript提交表单:目录:1:js 字符串长度限制、判断字符长度、js限制输入、限制不能输入、textarea 长度限制2.:js判断汉字、判断是否汉字、只能输入汉字3:js判断是否输入英文、只能输入英文4:js只能输入数字,判断数字、验证数字、检测数字、判断是否为数字、只能输入数字5:只能输入英文字符和数字6: js email验证、js 判断email 、信箱/邮箱格式验证7:js字符过滤,屏蔽关键字8:js密码验证、判断密码2.1: js 不为空、为空或不是对象、判断为空、判断不为空2.2:比较两个表单项的值是否相同2.3:表单只能为数字和"_",2.4:表单项输入数值/长度限定2.5:中文/英文/数字/邮件地址合法性判断2.6:限定表单项不能输入的字符2.7表单的自符控制2.8:form文本域的通用校验函数1. 长度限制<script>function test(){if(document.a.b.value.length>50){alert("不能超过50个字符!");document.a.b.focus();return false;}}</script><form name=a onsubmit="return test()"><textarea name="b" cols="40" wrap="VIRTUAL" rows="6"></textarea><input type="submit" name="Submit" value="check"></form>2. 只能是汉字<input onkeyup="value="/oblog/value.replace(/[^\u4E00-\u9FA5]/g,'')"> 3." 只能是英文<script language=javascript>function onlyEng(){if(!(event.keyCode>=65&&event.keyCode<=90))event.returnvalue=false;}</script><input onkeydown="onlyEng();">4. 只能是数字<script language=javascript>function onlyNum(){if(!((event.keyCode>=48&&event.keyCode<=57)||(event.keyCode>=96&&even t.keyCode<=105)))//考虑小键盘上的数字键event.returnvalue=false;}</script><input onkeydown="onlyNum();">5. 只能是英文字符和数字<input onkeyup="value="/oblog/value.replace(/[\W]/g,"'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('t ext').replace(/[^\d]/g,''))">6. 验证油箱格式<SCRIPT LANGUAGE=javascript RUNAT=Server>function isEmail(strEmail) {if(strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)return true;elsealert("oh");}</SCRIPT><input type=text onblur=isEmail(this.value)>7. 屏蔽关键字(这里屏蔽***和****)<script language="javascript1.2">function test() {if((a.b.value.indexOf ("***") == 0)||(a.b.value.indexOf ("****") == 0)){ alert(":)");a.b.focus();return false;}}</script><form name=a onsubmit="return test()"><input type=text name=b><input type="submit" name="Submit" value="check"></form>8. 两次输入密码是否相同<FORM METHOD=POST ACTION=""><input type="password" id="input1"><input type="password" id="input2"><input type="button" value="test" onclick="check()"></FORM><script>function check(){with(document.all){if(input1.value!=input2.value){alert("false")input1.value = "";input2.value = "";}else document.forms[0].submit();}}</script>够了吧 :)屏蔽右键很酷oncontextmenu="return false" ondragstart="return false" onselectstart="return false"加在body中二2.1 表单项不能为空<script language="javascript"><!--function CheckForm(){if (.value.length == 0) {alert("请输入您姓名!");.focus();return false;}return true;}--></script>2.2 比较两个表单项的值是否相同<script language="javascript"><!--function CheckForm()if (document.form.PWD.value != document.form.PWD_Again.value) { alert("您两次输入的密码不一样!请重新输入.");document.ADDUser.PWD.focus();return false;}return true;}--></script>2.3 表单项只能为数字和"_",用于电话/银行帐号验证上,可扩展到域名注册等<script language="javascript"><!--function isNumber(String){var Letters = "1234567890-"; //可以自己增加可输入值var i;var c;if(String.charAt( 0 )=='-')return false;if( String.charAt( String.length - 1 ) == '-' )return false;for( i = 0; i < String.length; i ++ ){c = String.charAt( i );if (Letters.indexOf( c ) < 0)return false;}return true;}function CheckForm(){if(! isNumber(document.form.TEL.value)) {alert("您的电话号码不合法!");document.form.TEL.focus();return false;}return true;}--></script>2.4 表单项输入数值/长度限定<script language="javascript"><!--function CheckForm(){if (document.form.count.value > 100 || document.form.count.value < 1) {alert("输入数值不能小于零大于100!");document.form.count.focus();return false;}if (document.form.MESSAGE.value.length<10){alert("输入文字小于10!");document.form.MESSAGE.focus();return false;}return true;}//--></script>2.5 中文/英文/数字/邮件地址合法性判断<SCRIPT LANGUAGE="javascript"><!--function isEnglish(name) //英文值检测{if(name.length == 0)return false;for(i = 0; i < name.length; i++) {if(name.charCodeAt(i) > 128)return false;}return true;}function isChinese(name) //中文值检测{if(name.length == 0)return false;for(i = 0; i < name.length; i++) {if(name.charCodeAt(i) > 128)return true;}return false;}function isMail(name) // E-mail值检测{if(! isEnglish(name))return false;i = name.indexOf(" at ");j = name dot lastIndexOf(" at ");if(i == -1)return false;if(i != j)return false;if(i == name dot length)return false;return true;}function isNumber(name) //数值检测{if(name.length == 0)return false;for(i = 0; i < name.length; i++) {if(name.charAt(i) < "0" || name.charAt(i) > "9") return false;}return true;}function CheckForm(){if(! isMail(form.Email.value)) {alert("您的电子邮件不合法!");form.Email.focus();return false;}if(! isEnglish(.value)) {alert("英文名不合法!");.focus();return false;}if(! isChinese(name.value)) {alert("中文名不合法!");name.focus();return false;}if(! isNumber(form.PublicZipCode.value)) {alert("邮政编码不合法!");form.PublicZipCode.focus();return false;}return true;}//--></SCRIPT>2.6 限定表单项不能输入的字符<script language="javascript"><!--function contain(str,charset)// 字符串包含测试函数{var i;for(i=0;i<charset.length;i++)if(str.indexOf(charset.charAt(i))>=0)return true;return false;}function CheckForm(){if ((contain(.value, "%\(\)><")) || (contain(document.form.MESSAGE.value, "%\(\)><"))) {alert("输入了非法字符");.focus();return false;}return true;}//--></script>1. 检查一段字符串是否全由数字组成---------------------------------------<script language="Javascript"><!--function checkNum(str){return str.match(/\D/)==null} alert(checkNum("1232142141"))alert(checkNum("123214214a1"))// --></script>2. 怎么判断是否是字符---------------------------------------if (/[^\x00-\xff]/g.test(s)) alert("含有汉字");else alert("全是字符");3. 怎么判断是否含有汉字---------------------------------------if (escape(str).indexOf("%u")!=-1) alert("含有汉字"); else alert("全是字符");4. 邮箱格式验证//函数名:chkemail//功能介绍:检查是否为Email Address//参数说明:要检查的字符串//返回值:0:不是 1:是function chkemail(a){ var i=a.length;var temp = a.indexOf('@');var tempd = a.indexOf('.');if (temp > 1) {if ((i-temp) > 3){if ((i-tempd)>0){return 1;}}}return 0;}5. 数字格式验证--------------------------------------- //函数名:fucCheckNUM//功能介绍:检查是否为数字//参数说明:要检查的数字//返回值:1为是数字,0为不是数字function fucCheckNUM(NUM){var i,j,strTemp;strTemp="0123456789";if ( NUM.length== 0)return 0for (i=0;i<NUM.length;i++){j=strTemp.indexOf(NUM.charAt(i));if (j==-1){//说明有字符不是数字return 0;}}//说明是数字return 1;}6. 电话号码格式验证//函数名:fucCheckTEL//功能介绍:检查是否为电话号码//参数说明:要检查的字符串//返回值:1为是合法,0为不合法function fucCheckTEL(TEL){var i,j,strTemp;strTemp="0123456789-()# ";for (i=0;i<TEL.length;i++){j=strTemp.indexOf(TEL.charAt(i));if (j==-1){//说明有字符不合法return 0;}}//说明合法return 1;}7. 判断输入是否为中文的函数--------------------------------------- function ischinese(s){var ret=true;for(var i=0;i<s.length;i++)ret=ret && (s.charCodeAt(i)>=10000); return ret;}8. 综合的判断用户输入的合法性的函数--------------------------------------- <script language="javascript">//限制输入字符的位数开始//m是用户输入,n是要限制的位数function issmall(m,n){if ((m<n) && (m>0)){return(false);}else{return(true);}}9. 判断密码是否输入一致function issame(str1,str2){if (str1==str2){return(true);}else{return(false);}}10. 判断用户名是否为数字字母下滑线---------------------------------------function notchinese(str){var reg=/[^A-Za-z0-9_]/gif (reg.test(str)){return (false);}else{return(true); }}2.8. form文本域的通用校验函数---------------------------------------作用:检测所有必须非空的input文本,比如姓名,账号,邮件地址等等。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
28. 检查一段字符串是否全由数字组成
<script language="javascript"><!--
function checkNum(str){return str.match(//D/)==null}
alert(checkNum("1232142141"
alert(checkNum("123214214a1"
function getIE(E){
var t=e.offsetTop;
var l=e.offsetLeft;
while(e=e.offsetParent){
t+=e.offsetTop;
l+=e.offsetLeft;
}
alert("top="+t+"/nleft="+l);
}
</script>
<form name="form1" method="post" action="mailt****@***.com" enctype="text/plain">
<input type=submit>
</form>
25.在打开的子窗口刷新父窗口的代码里如何写?
window.opener.location.reload()
r.collapse(true);
r.select();
}
</script>
<input type=text name=text1 value="123" onfocus="cc()">
15. 判断上一页的来源
javascript:
document.referrer
16. 最小化、最大化、关闭窗口
next
end function
</script><BODY>
<INPUT name="radio1" type="radio" value="style" checked>style
<INPUT name="radio1" type="radio" value="barcode">Barcode
<object id=hh1 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<param name="Command" value="Minimize"></object>
<object id=hh2 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<param name="Command" value="Maximize"></object>
<OBJECT id=hh3 classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<PARAM NAME="Command" value="Close"></OBJECT>
3. onpaste="return false" 不准粘贴
4. oncopy="return false;" oncut="return false;" 防止复制
5. <link rel="Shortcut Icon" href="favicon.ico"> IE地址栏前换成自己的图标
本例适用于IE
17.屏蔽功能键Shift,Alt,Ctrl
<script>
function look(){
if(event.shiftKey)
alert("禁止按Shift键!"; //可以换成ALT CTRL
}
document.onkeydown=look;
</script>
12.删除时确认
<a href=`javascript:if(confirm("确实要删除吗?"location="boos.asp?&areyou=删除&page=1"`>删
除</a>
13. 取得控件的绝对位置
//javascript
<script language="javascript">
25.在打开的子窗口刷新父窗口的代码里如何写?
window.opener.location.reload()
26.如何设定打开页面的大小
<body onload="top.resizeTo(300,200);">
打开页面的位置<body onload="top.moveBy(300,200);">
1. oncontextmenu="window.event.returnvalue=false" 将彻底屏蔽鼠标右键
<table border oncontextmenu=return(false)><td>no</table> 可用于Table
2. <body onselectstart="return false"> 取消选取、防止复制
21.让弹出窗口总是在最上面:
<body onblur="this.focus();">
22.不要滚动条?
让竖条没有:
<body style=`overflow:-Scroll;overflow-y:hidden`>
</body>
让横条没有:
<body style=`overflow:-Scroll;overflow-x:hidden`>
6. <link rel="Bookmark" href="favicon.ico"> 可以在收藏夹中显示出你的图标
7. <input style="ime-mode:-Disabled"> 关闭输入法
8. 永远都会带着框架
<script language="javascript"><!--
function cc(dd,dadd)
{
//可以加上错误处理
var a = new Date(dd)
a = a.valueOf()
a = a - dadd * 24 * 60 * 60 * 1000
a = new Date(A)
alert(a.getFullYear() + "年" + (a.getMonth() + 1) + "月" + a.getDate() + "日"
// --></SCRIPT>
10. 网页将不能被另存为
<noscript><iframe src=*.html></iframe></noscript>
11. <input type=button value=查看网页源代码
onclick="window.location = `view-source:`+ /`";>
}
cc("12/23/2002",2)
</script>
33. 选择了哪一个Radio
<HTML><script language="vbscript">
function checkme()
for each ob in radio1
if ob.checked then window.alert ob.value
1 solid #000000"></textarea>
20.<div><span>&<layer>的区别?
<div>(division)用来定义大段的页面元素,会产生转行
<span>用来定义同一行内的元素,跟<div>的唯一区别是不产生转行
<layer>是ns的标记,ie不支持,相当于<div>
14. 光标是停在文本框文字的最后
<script language="javascript">
function cc()
{
var e = event.srcElement;
var r =e.createTextRange();
r.moveStart(`character`,e.value.length);