Home > Web Front-end > JS Tutorial > body text

Collection of 55 classic techniques commonly used in Javascript_javascript techniques

WBOY
Release: 2016-05-16 19:10:41
Original
980 people have browsed it

1. oncontextmenu="window.event.returnValue=false" will completely block the right mouse button

no
Can be used in Table

2. Cancel selection and prevent copying

3. onpaste="return false" No pasting allowed

4. oncopy="return false; "oncut="return false;" Prevent copying

5. Change the IE address bar to your own icon

6. You can display your icon in your favorites Icon


7. Close the input method


8. Always carry the frame




9 . Prevent being framed



";



11. 12. Confirm when deleting
Delete



13. Get the absolute position of the control
//Javascript


/ /VBScript



14. The cursor is stopped at the end of the text box text






15 . Determine the source of the previous page
javascript: document.referrer
16. Minimize, maximize, close the window












This example applies to IE


17. Block function keys Shift, Alt, Ctrl

18. Web pages will not be cached




or

19. How to make the form non-convex?


or


20. What is the difference between
&
?
(division) is used to define large sections of page elements, which will cause line breaks.

is used to define elements in the same line. The only difference with
is that it will not cause line breaks.
is the mark of ns, which is not supported by IE. It is equivalent to



21. Let the pop-up window always be at the top:


22. No scroll bars?
Let there be no vertical bars:


Let there be no horizontal bars:


Remove both? Easier

Collection of 55 classic techniques commonly used in Javascript_javascript techniques

23. How to remove the dotted lines around the image after clicking on the image link?



24. Email processing submission form
enctype="text/plain">
<script><!-- <BR>if (window == top)top.location.href = "frames.htm"; //frames.htm为框架网页 <BR>// --></script> <script><!-- <BR>if (top.location != self.location)top.location=self.location; <BR>// --></script><script> <BR>function getIE(e){ <BR>var t=e.offsetTop; <BR>var l=e.offsetLeft; <BR>while(e=e.offsetParent){ <BR>t+=e.offsetTop; <BR>l+=e.offsetLeft; <BR>} <BR>alert("top="+t+"/nleft="+l); <BR>} <BR></script> <script><!-- <BR>function getIE() <BR>dim t,l,a,b <BR>set a=document.all.img1 <BR>t=document.all.img1.offsetTop <BR>l=document.all.img1.offsetLeft <BR>while a.tagName<>"BODY" <BR>set a = a.offsetParent <BR>t=t+a.offsetTop <BR>l=l+a.offsetLeft <BR>wend <BR>msgbox "top="&t&chr(13)&"left="&l,64,"得到控件的位置" <BR>end function <BR>--></script><script> <BR>function cc() <BR>{ <BR>var e = event.srcElement; <BR>var r =e.createTextRange(); <BR>r.moveStart("character",e.value.length); <BR>r.collapse(true); <BR>r.select(); <BR>} <BR></script><script> <BR>function look(){ <BR>if(event.shiftKey) <BR>alert("禁止按Shift键!"); //可以换成ALT CTRL <BR>} <BR>document.onkeydown=look; <BR></script>25. Refresh the parent window in the opened child window How to write it in the code?
window.opener.location.reload()


26.如何设定打开页面的大小

打开页面的位置


27.在页面中如何加入不是满铺的背景图片,拉动页面时背景图不动 
 


28. 检查一段字符串是否全由数字组成
<script><!-- <BR>function checkNum(str){return str.match(//D/)==null} <BR>alert(checkNum("1232142141")) <BR>alert(checkNum("123214214a1")) <BR>// --></script>


29. 获得一个窗口的大小
document.body.clientWidth; document.body.clientHeight


30. 怎么判断是否是字符
if (/[^/x00-/xff]/g.test(s)) alert("含有汉字");
else alert("全是字符");


31.TEXTAREA自适应文字行数的多少



32. 日期减去天数等于第二个日期
<script> <BR>function cc(dd,dadd) <BR>{ <BR>//可以加上错误处理 <BR>var a = new Date(dd) <BR>a = a.valueOf() <BR>a = a - dadd * 24 * 60 * 60 * 1000 <BR>a = new Date(a) <BR>alert(a.getFullYear() + "年" + (a.getMonth() + 1) + "月" + a.getDate() + "日") <BR>} <BR>cc("12/23/2002",2) <BR></script>


33. 选择了哪一个Radio
<script> <BR>function checkme() <BR>for each ob in radio1 <BR>if ob.checked then <BR>window.alert ob.value <BR>next <BR>end function <BR></script>
Style
Barcode




34.脚本永不出错
<script> <BR><!-- Hide <BR>function killErrors() { <BR>return true; <BR>} <BR>window.onerror = killErrors; <BR>// --> <BR></script>


35.ENTER键可以让光标移到下一个输入框



36. 检测某个网站的链接速度:
把如下代码加入区域中:
<script> <BR>tim=1 <BR>setInterval("tim++",100) <BR>b=1 <BR>var autourl=new Array() <BR>autourl[1]=1000){this.resized=true;this.style.width=1000;}" align=absMiddle border=0>www.njcatv.net" <BR>autourl[2]="javacool.3322.net" <BR>autourl[3]=1000){this.resized=true;this.style.width=1000;}" align=absMiddle border=0>www.sina.com.cn" <BR>autourl[4]="www.nuaa.edu.cn" <BR>autourl[5]=1000){this.resized=true;this.style.width=1000;}" align=absMiddle border=0>www.cctv.com" <BR>function butt(){ <BR>***("<form name=autof>") <BR>for(var i=1;i<autourl.length;i++) <BR>***("<input type=text name=txt"+i+" size=10 value="/测试中……> =》<input type=text <BR>name=url"+i+" size=40> =》<input type=button value="/blog/GO <BR>onclick=window.open(this.form.url"+i+".value)><br>") <BR>***("<input type=submit value=刷新></script>
")
}
butt()
function auto(url){
document.forms[0]["url"+b].value=url
if(tim>200)
{document.forms[0]["txt"+b].value="/链接超时"}
else
{document.forms[0]["txt"+b].value="/blog/时间"+tim/10+"秒"}
b++
}
function run(){for(var i=1;ionerror=auto("http://"+autourl+"")>")}
run()


37. 各种样式的光标
auto :标准光标
default :标准箭头
hand :手形光标
wait :等待光标
text :I形光标
vertical-text :水平I形光标
no-drop :不可拖动光标
not-allowed :无效光标
help :?帮助光标
all-scroll :三角方向标
move :移动标
crosshair :十字标
e-resize
n-resize
nw-resize
w-resize
s-resize
se-resize
sw-resize


38.页面进入和退出的特效
进入页面
推出页面  
这个是页面被载入和调出时的一些特效。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 以上22种随机选择一种


39.在规定时间内跳转
 


40.网页是否被检索

  其中属性值有以下一些:
  属性值为"all": 文件将被检索,且页上链接可被查询;
  属性值为"none": 文件不被检索,而且不查询页上的链接;
  属性值为"index": 文件将被检索;
  属性值为"follow": 查询页上的链接;
  属性值为"noindex": 文件不检索,但可被查询链接;
  属性值为"nofollow": 文件不被检索,但可查询页上的链接。


41、email地址的分割
把如下代码加入区域中
webmaster@sina.com


42、流动边框效果的表格
把如下代码加入区域中
<script> <BR>l=Array(6,7,8,9,'a','b','b','c','d','e','f') <BR>Nx=5;Ny=35 <BR>t="<table border=0 cellspacing=0 cellpadding=0 height="+((Nx+2)*16)+"><tr>" <BR>for(x=Nx;x<Nx+Ny;x++) <BR>t+="<td width=16 id=a_mo"+x+"> " <BR>t+="<tr><td width=10 id=a_mo"+(Nx-1)+"> <td colspan="+(Ny-2)+" rowspan="+(Nx)+"> <td width=16 id=a_mo"+(Nx+Ny)+">" <BR>for(x=2;x<=Nx;x++) <BR>t+="<tr><td width=16 id=a_mo"+(Nx-x)+"> <td width=16 id=a_mo"+(Ny+Nx+x-1)+"> " <BR>t+="<tr>" <BR>for(x=Ny;x>0;x--) <BR>t+="<td width=16 id=a_mo"+(x+Nx*2+Ny-1)+"> " <BR>***(t+"") <BR>var N=Nx*2+Ny*2 <BR>function f1(y){ <BR>for(i=0;i<N;i++){ <BR>c=(i+y)%20;if(c>10)c=20-c <BR>document.all["a_mo"+(i)].bgColor=""""#0000"+l[c]+l[c]+"'"} <BR>y++ <BR>setTimeout('f1('+y+')','1')} <BR>f1(1) <BR></script>


43、JavaScript主页弹出窗口技巧
窗口中间弹出
<script> <BR>window.open("http://www.cctv.com","","width=400,height=240,top="+(screen.availHeight-240)/2+",left="+(screen.availWidth-400)/2); <BR></script>
============


<script> <BR>function WinOpen() { <BR> msg=open("","DisplayWindow","toolbar=no,directories=no,menubar=no"); <BR> msg.***("<HEAD><TITLE>哈 罗!"); <BR> msg.***("<CENTER><H1>酷 毙 了!<h2>这 是<B>JavaScript所 开 的 视 窗!"); <BR>} <BR></script>







==============
一、在下面的代码中,你只要单击打开一个窗口,即可链接到赛迪网。而当你想关闭时,只要单击一下即可关闭刚才打开的窗口。
  代码如下: 
  <script> <BR>  <!-- <BR>  function openclk() { <BR>  another=open('1000){this.resized=true;this.style.width=1000;}" align=absMiddle border=0>http://www.ccidnet.com','NewWindow'); <BR>  } <BR>  function closeclk() { <BR>  another.close(); <BR>  } <BR>  //--> <BR>  </script> 
  
 
   
  
 
   
  
 
  二、上面的代码也太静了,为何不来点动感呢?如果能给页面来个降落效果那该多好啊! 
  代码如下: 
  <script> <BR>  function drop(n) { <BR>  if(self.moveBy){ <BR>  self.moveBy (0,-900); <BR>  for(i = n; i > 0; i--){ <BR>  self.moveBy(0,3); <BR>  } <BR>  for(j = 8; j > 0; j--){ <BR>  self.moveBy(0,j); <BR>  self.moveBy(j,0); <BR>  self.moveBy(0,-j); <BR>  self.moveBy(-j,0); <BR>  } <BR>  } <BR>  } <BR>  </script> 
   
  三、讨厌很多网站总是按照默认窗口打开,如果你能随心所欲控制打开的窗口那该多好。 
  代码如下: 
  <script> <BR>  <!-- Begin <BR>  function popupPage(l, t, w, h) { <BR>  var windowprops = "location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes" + <BR>  ",left=" + l + ",top=" + t + ",width=" + w + ",height=" + h; <BR>  var URL = "http://www.80cn.com"; <BR>  popup = window.open(URL,"MenuPopup",windowprops); <BR>  } <BR>  // End --> <BR>  </script> 
   
   
   
   
  
 
  
 
  
  <br>  打开页面的参数<br>  <br>  离开左边的距离: <input> pixels  <br>  离开右边的距离: <input> pixels  <br>  窗口的宽度: <input> pixels  <br>  窗口的高度: <input> pixels  <br>  
Copy after login
 
  
 
  this.form.height.value)"> 
  
 
  
 
  
你只要在相对应的对话框中输入一个数值即可,将要打开的页面的窗口控制得很好。 


44、页面的打开移动
把如下代码加入区域中
<script> <BR><!-- Begin <BR>for (t = 2; t > 0; t--) { <BR>for (x = 20; x > 0; x--) { <BR>for (y = 10; y > 0; y--) { <BR>parent.moveBy(0,-x); <BR> } <BR>} <BR>for (x = 20; x > 0; x--) { <BR>for (y = 10; y > 0; y--) { <BR>parent.moveBy(0,x); <BR> } <BR>} <BR>for (x = 20; x > 0; x--) { <BR>for (y = 10; y > 0; y--) { <BR>parent.moveBy(x,0); <BR> } <BR>} <BR>for (x = 20; x > 0; x--) { <BR>for (y = 10; y > 0; y--) { <BR>parent.moveBy(-x,0); <BR> } <BR> } <BR>} <BR>//--> <BR>// End --> <BR></script>


45、显示个人客户端机器的日期和时间
<script> <BR><!-- Hiding <BR> today = new Date() <BR> ***("现 在 时 间 是: ",today.getHours(),":",today.getMinutes()) <BR> ***("<br>今 天 日 期 为: ", today.getMonth()+1,"/",today.getDate(),"/",today.getYear()); <BR>// end hiding contents --> <BR></script>


46、自动的为你每次产生最後修改的日期了: 


This is a simple HTML- page.


Last changes:
   <script> <BR> <!-- hide script from old browsers <BR> ***(document.lastModified) <BR> // end hiding contents --> <BR> </script>




47、不能为空和邮件地址的约束:


<script> <BR><!-- Hide <BR>function test1(form) { <BR> if (form.text1.value == "") <BR> alert("您 没 写 上 任 何 东 西, 请 再 输 入 一 次 !") <BR> else { <BR> alert("嗨 "+form.text1.value+"! 您 已 输 入 完 成 !"); <BR> } <BR>} <BR>function test2(form) { <BR> if (form.text2.value == "" || <BR> form.text2.value.indexOf('@', 0) == -1) <BR> alert("这 不 是 正 确 的 e-mail address! 请 再 输 入 一 次 !"); <BR> else alert("您 已 输 入 完 成 !"); <BR>} <BR>// --> <BR></script>



Enter your name:




Enter your e-mail address:






48、跑马灯


<script> <BR><!-- Hide <BR>var scrtxt="怎麽样 ! 很酷吧 ! 您也可以试试."+"Here goes your message the visitors to your <BR>page will "+"look at for hours in pure fascination..."; <BR>var lentxt=scrtxt.length; <BR>var width=100; <BR>var pos=1-width; <BR>function scroll() { <BR> pos++; <BR> var scroller=""; <BR> if (pos==lentxt) { <BR> pos=1-width; <BR> } <BR> if (pos<0) { <BR> for (var i=1; i<=Math.abs(pos); i++) { <BR> scroller=scroller+" ";} <BR> scroller=scroller+scrtxt.substring(0,width-i+1); <BR> } <BR> else { <BR> scroller=scroller+scrtxt.substring(pos,width+pos); <BR> } <BR> window.status = scroller; <BR> setTimeout("scroll()",150); <BR> } <BR>//--> <BR></script>


这里可显示您的网页 !




49、在网页中用按钮来控制前页,后页和主页的显示。



      
      
      



50、查看某网址的源代码
把如下代码加入区域中
<script> <BR>function add() <BR>{ <BR>var ress=document.forms[0].luxiaoqing.value <BR>window.location="view-source:"+ress; <BR>} <BR></script>
输入要查看源代码的URL地址:







51、title显示日期
把如下代码加入区域中:
<script> <BR><!--hide <BR>var isnMonth = new <BR>Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"); <BR>var isnDay = new <BR>Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六","星期日"); <BR>today = new Date () ; <BR>Year=today.getYear(); <BR>Date=today.getDate(); <BR>if (document.all) <BR>document.title="今天是: "+Year+"年"+isnMonth[today.getMonth()]+Date+"日"+isnDay[today.getDay()] <BR>//--hide--> <BR></script>


52、显示所有链接
把如下代码加入区域中
<script> <BR><!-- <BR>function extractlinks(){ <BR>var links=document.all.tags("A") <BR>var total=links.length <BR>var win2=window.open("","","menubar,scrollbars,toolbar") <BR>win2.***("<font size='2'>一共有"+total+"个连接<br>") <BR>for (i=0;i<total;i++){ <BR>win2.***("<font size='2'>"+links[i].outerHTML+"<br>") <BR>} <BR>} <BR>//--> <BR></script>



53、回车键换行
把如下代码加入区域中
<script> <BR>function handleEnter (field, event) { <BR> var keyCode = event.keyCode ? event.keyCode : event.which ? <BR>event.which : event.charCode; <BR> if (keyCode == 13) { <BR> var i; <BR> for (i = 0; i < field.form.elements.length; i++) <BR> if (field == field.form.elements[i]) <BR> break; <BR> i = (i + 1) % field.form.elements.length; <BR> field.form.elements[i].focus(); <BR> return false; <BR> } <BR> else <BR> return true; <BR>} <BR></script>





source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template