现在的位置: 首页 > 综合 > 正文

javascript 常用代码大全

2013年09月01日 ⁄ 综合 ⁄ 共 16983字 ⁄ 字号 评论关闭
  1. //打开模式对话框 
  2. function doSelectUser(txtId) 
  3.       strFeatures="dialogWidth=500px;dialogHeight=360px;center=yes;
  4. middle=yes ;help=no;status=no;scroll=no"; 
  5.       var url,strReturn; 
  6.   
  7.       url="selUser.ASPx"
  8.         
  9.       strReturn=window.showModalDialog(url,'',strFeatures);   
  10. //返回模式对话框的值 
  11. function okBTn_onclick() 
  12. var commstr='';          
  13.       
  14. window.returnValue=commstr; 
  15.       window.close() 
  16. 全屏幕打开 IE 窗口 
  17. var winWidth=screen.availWidth ; 
  18. var winHeight=screen.availHeight-20; 
  19. window.open("main.aspx","surveyWindow","toolbar=no,width="+ winWidth  +",height="+ winHeight  +",top=0,left=0,scrollbars=yes,resizable=yes,center:yes,statusbars=yes"); 
  20. break 
  21. //脚本中中使用XML 
  22. function initialize() { 
  23.   var xmlDoc 
  24.   var xslDoc 
  25.   xmlDoc = new ActiveXObject('Microsoft.XMLDOM'
  26.   xmlDoc.async = false
  27.   xslDoc = new ActiveXObject('Microsoft.XMLDOM'
  28.   xslDoc.async = false
  29.  xmlDoc.load("tree.xml"
  30.   xslDoc.load("tree.xsl"
  31.   
  32.   
  33.   folderTree.innerHtml = xmlDoc.documentElement.transformNode(xslDoc) 
  34. 一、验证类 
  35. 1、数字验证内 
  36.   1.1 整数 
  37.   1.2 大于0的整数 (用于传来的ID的验证) 
  38.   1.3 负整数的验证 
  39.   1.4 整数不能大于iMax
  40.  1.5 整数不能小于iMin 
  41. 2、时间类 
  42.   2.1 短时间,形如 (13:04:06) 
  43.   2.2 短日期,形如 (2003-12-05) 
  44.   2.3 长时间,形如 (2003-12-05 13:04:06) 
  45.   2.4 只有年和月。形如(2003-05,或者2003-5) 
  46.   2.5 只有小时和分钟,形如(12:03) 
  47. 3、表单类 
  48.   3.1 所有的表单的值都不能为空 
  49.   3.2 多行文本框的值不能为空。 
  50.   3.3 多行文本框的值不能超过sMaxStrleng 
  51.   3.4 多行文本框的值不能少于sMixStrleng 
  52.   3.5 判断单选框是否选择。 
  53.   3.6 判断复选框是否选择. 
  54.   3.7 复选框的全选,多选,全不选,反选 
  55.   3.8 文件上传过程中判断文件类型 
  56. 4、字符类 
  57.   4.1 判断字符全部由a-Z或者是A-Z的字字母组成 
  58.   4.2 判断字符由字母和数字组成。 
  59.   4.3 判断字符由字母和数字,下划线,点号组成.且开头的只能是下划线和字母 
  60.   4.4 字符串替换函数.Replace(); 
  61. 5、浏览器类 
  62.   5.1 判断浏览器的类型 
  63.   5.2 判断ie的版本 
  64.   5.3 判断客户端的分辨率 
  65.   
  66. 6、结合类 
  67.   6.1 email的判断。 
  68.   6.2 手机号码的验证 
  69.   6.3 身份证的验证 
  70.   
  71. 二、功能类 
  72. 1、时间与相关控件类 
  73.   1.1 日历 
  74.   1.2 时间控件 
  75.   1.3 万年历 
  76.   1.4 显示动态显示时钟效果(文本,如OA中时间) 
  77.   1.5 显示动态显示时钟效果 (图像,像手表) 
  78. 2、表单类 
  79.   2.1 自动生成表单 
  80.   2.2 动态添加,修改,删除下拉框中的元素 
  81.   2.3 可以输入内容的下拉框 
  82.   2.4 多行文本框中只能输入iMax文字。如果多输入了,自动减少到iMax个文字(多用于短信发送) 
  83.   
  84. 3、打印类 
  85.   3.1 打印控件 
  86. 4、事件类 
  87.   4.1 屏蔽右键 
  88.   4.2 屏蔽所有功能键 
  89.   4.3 --> 和<-- F5 F11,F9,F1 
  90. 4.4 屏蔽组合键ctrl+N 
  91. 5、网页设计类 
  92.   5.1 连续滚动的文字,图片(注意是连续的,两段文字和图片中没有空白出现) 
  93.   5.2 html编辑控件类 
  94.   5.3 颜色选取框控件 
  95.   5.4 下拉菜单 
  96.   5.5 两层或多层次的下拉菜单 
  97.   5.6 仿IE菜单的按钮。(效果如rongshuxa.com的导航栏目) 
  98.   5.7 状态栏,title栏的动态效果(例子很多,可以研究一下) 
  99.   5.8 双击后,网页自动滚屏 
  100. 6、树型结构。 
  101.   6.1 asp+SQL版 
  102.   6.2 asp+xml+sql版 
  103.   6.3 Java+sql或者java+sql+xml 
  104. 7、无边框效果的制作 
  105. 8、连动下拉框技术 
  106. 9、文本排序 
  107. 10,画图类,含饼、柱、矢量贝滋曲线 
  108. 11,操纵客户端注册表类 
  109. 12,DIV层相关(拖拽、显示、隐藏、移动、增加) 
  110. 13,TABLAE相关(客户端动态增加行列,模拟进度条,滚动列表等) 
  111. 14,各种<object classid=>相关类,如播放器,flash与脚本互动等 
  112. 16, 刷新/模拟无刷新 异步调用类(XMLHttp或iframe,frame) 
  113. 一、验证类 
  114. 1、数字验证内 
  115.   1.1 整数 
  116.       /^(-/+)?/d+$/.test(str) 
  117.   1.2 大于0的整数 (用于传来的ID的验证) 
  118.       /^/d+$/.test(str) 
  119.   1.3 负整数的验证 
  120.       /^-/d+$/.test(str) 
  121. 2、时间类 
  122.   2.1 短时间,形如 (13:04:06) 
  123.       function isTime(str) 
  124.       { 
  125.         var a = str.match(/^(/d{1,2})(:)?(/d{1,2})/2(/d{1,2})$/);
  126. if (a == null) {alert('输入的参数不是时间格式'); return false;} 
  127.         if (a[1]>24 a[3]>60 a[4]>60) 
  128.         { 
  129.           alert("时间格式不对"); 
  130.           return false 
  131.         } 
  132.         return true
  133.       } 
  134.   2.2 短日期,形如 (2003-12-05) 
  135.       function strDateTime(str) 
  136.       { 
  137.          var r = str.match(/^(/d{1,4})(-//)(/d{1,2})/2(/d{1,2})$/); 
  138.          if(r==null)return false
  139.          var d= new Date(r[1], r[3]-1, r[4]); 
  140.          return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]); 
  141.       } 
  142.   2.3 长时间,形如 (2003-12-05 13:04:06) 
  143.       function strDateTime(str) 
  144.       { 
  145.         var reg = /^(/d{1,4})(-//)(/d{1,2})/2(/d{1,2}) (/d{1,2}):(/d{1,2}):(/d{1,2})$/; 
  146.         var r = str.match(reg); 
  147.         if(r==null)return false
  148.         var d= new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]); 
  149.         return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]&&d.getHours()==r[5]&&d.getMinutes()==r[6]&&d.getSeconds()==r[7]);
  150.   2.4 只有年和月。形如(2003-05,或者2003-5) 
  151.   2.5 只有小时和分钟,形如(12:03) 
  152. 3、表单类 
  153.   3.1 所有的表单的值都不能为空 
  154.       <input onblur="if(this.value.replace(/^/s+/s+$/g,'')=='')alert('不能为空!')"
  155.   3.2 多行文本框的值不能为空。 
  156.   3.3 多行文本框的值不能超过sMaxStrleng 
  157.   3.4 多行文本框的值不能少于sMixStrleng 
  158.   3.5 判断单选框是否选择。 
  159.   3.6 判断复选框是否选择. 
  160.   3.7 复选框的全选,多选,全不选,反选 
  161.   3.8 文件上传过程中判断文件类型 
  162. 4、字符类 
  163.   4.1 判断字符全部由a-Z或者是A-Z的字字母组成 
  164.       <input onblur="if(/[^a-zA-Z]/g.test(this.value))alert('有错')"
  165.   4.2 判断字符由字母和数字组成。 
  166.       <input onblur="if(/[^0-9a-zA-Z]/g.test(this.value))alert('有错')"
  167.   4.3 判断字符由字母和数字,下划线,点号组成.且开头的只能是下划线和字母 
  168.       /^([a-zA-z_]{1})([/w]*)$/g.test(str) 
  169.   4.4 字符串替换函数.Replace(); 
  170. 5、浏览器类 
  171.   5.1 判断浏览器的类型 
  172.       window.navigator.appName 
  173.   5.2 判断ie的版本 
  174.       window.navigator.appVersion 
  175.   5.3 判断客户端的分辨率 
  176.       window.screen.height;  window.screen.width; 
  177.   
  178. 6、结合类 
  179.   6.1 email的判断。 
  180.       function ismail(mail) 
  181.       { 
  182.         return(new RegEXP(/^/w+((-/w+)(/./w+))*/@[A-Za-z0-9]+((/.-)[A-Za-z0-9]+)*/.[A-Za-z0-9]+$/).test(mail)); 
  183.       } 
  184.   6.2 手机号码的验证 
  185.   6.3 身份证的验证 
  186.       function isIdCardNo(num) 
  187.       {
  188. if (isNaN(num)) {alert("输入的不是数字!"); return false;} 
  189.         var len = num.length, re; 
  190.         if (len == 15) 
  191.           re = new RegExp(/^(/d{6})()?(/d{2})(/d{2})(/d{2})(/d{3})$/); 
  192.         else if (len == 18) 
  193.           re = new RegExp(/^(/d{6})()?(/d{4})(/d{2})(/d{2})(/d{3})(/d)$/); 
  194.         else {alert("输入的数字位数不对!"); return false;} 
  195.         var a = num.match(re); 
  196.         if (a != null
  197.         { 
  198.           if (len==15) 
  199.           { 
  200.             var D = new Date("19"+a[3]+"/"+a[4]+"/"+a[5]); 
  201.             var B = D.getYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5]; 
  202.           } 
  203.           else 
  204.           { 
  205.             var D = new Date(a[3]+"/"+a[4]+"/"+a[5]); 
  206.             var B = D.getFullYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5]; 
  207.           } 
  208.           if (!B) {alert("输入的身份证号 "+ a[0] +" 里出生日期不对!"); return false;}
  209.         return true
  210.       } 
  211. 画图: 
  212. <OBJECT 
  213. id=S 
  214. style="LEFT: 0px; WIDTH: 392px; TOP: 0px; HEIGHT: 240px" 
  215. height=240 
  216. width=392 
  217. classid="clsid:369303C2-D7AC-11D0-89D5-00A0C90833E6"
  218. </OBJECT> 
  219. <SCRIPT> 
  220. S.DrawingSurface.ArcDegrees(0,0,0,30,50,60); 
  221. S.DrawingSurface.ArcRadians(30,0,0,30,50,60); 
  222. S.DrawingSurface.Line(10,10,100,100); 
  223. </SCRIPT> 
  224. 写注册表: 
  225. <SCRIPT> 
  226. var WshShell = WScript.CreateObject("WScript.Shell"); 
  227. WshShell.RegWrite ("HKCU//Software//ACME//FortuneTeller//", 1, "REG_BINARY"); 
  228. WshShell.RegWrite ("HKCU//Software//ACME//FortuneTeller//MindReader""Goocher!""REG_SZ"); 
  229. var bKey =    WshShell.RegRead ("HKCU//Software//ACME//FortuneTeller//"); 
  230. WScript.Echo (WshShell.RegRead ("HKCU//Software//ACME//FortuneTeller//MindReader")); 
  231. WshShell.RegDelete ("HKCU//Software//ACME//FortuneTeller//MindReader"); 
  232. WshShell.RegDelete ("HKCU//Software//ACME//FortuneTeller//");
  233. WshShell.RegDelete ("HKCU//Software//ACME//"); 
  234. </SCRIPT> 
  235. TABLAE相关(客户端动态增加行列) 
  236. <HTML> 
  237. <SCRIPT LANGUAGE="JScript"
  238. function numberCells() { 
  239.     var count=0; 
  240.     for (i=0; i < document.all.mytable.rows.length; i++) { 
  241.         for (j=0; j < document.all.mytable.rows(i).cells.length; j++) { 
  242.             document.all.mytable.rows(i).cells(j).innerText = count; 
  243.             count++; 
  244.         } 
  245.     } 
  246. </SCRIPT> 
  247. <BODY onload="numberCells()"
  248. <TABLE id=mytable border=1> 
  249. <TR><TH> </TH><TH> </TH><TH> </TH><TH> </TH></TR> 
  250. <TR><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR>
  251. <TR><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR> 
  252. </TABLE> 
  253. </BODY> 
  254. </HTML> 
  255. 1.身份证严格验证: 
  256. <script> 
  257. var aCity={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"
  258.   
  259. function cidInfo(sId){ 
  260. var iSum=0 
  261. var info="" 
  262. if(!/^/d{17}(/dx)$/i.test(sId))return false
  263. sId=sId.replace(/x$/i,"a"); 
  264. if(aCity[parseInt(sId.substr(0,2))]==null)return "Error:非法地区"
  265. sBirthday=sId.substr(6,4)+"-"+Number(sId.substr(10,2))+"-"+Number(sId.substr(12,2)); 
  266. var d=new Date(sBirthday.replace(/-/g,"/")) 
  267. if(sBirthday!=(d.getFullYear()+"-"+ (d.getMonth()+1) + "-" + d.getDate()))return "Error:非法生日"
  268. for(var i = 17;i>=0;i --) iSum += (Math.pow(2,i) % 11) * parseInt(sId.charAt(17 - i),11) 
  269. if(iSum%11!=1)return "Error:非法证号"
  270. return aCity[parseInt(sId.substr(0,2))]+","+sBirthday+","+(sId.substr(16,1)%2?"男":"女"
  271. document.write(cidInfo("380524198002300016"),"<br/>"); 
  272. document.write(cidInfo("340524198002300019"),"<br/>"
  273. document.write(cidInfo("340524197711111111"),"<br/>"
  274. document.write(cidInfo("34052419800101001x"),"<br/>"); 
  275. </script> 
  276. 2.验证IP地址 
  277. <SCRIPT LANGUAGE="javascript"
  278. function isip(s){ 
  279. var check=function(v){try{return (v<=255 && v>=0)}catch(x){return false}}; 
  280. var re=s.split("."
  281. return (re.length==4)?(check(re[0]) && check(re[1]) && check(re[2]) && check(re[3])):false 
  282. var s="202.197.78.129"
  283. alert(isip(s)) 
  284. </SCRIPT> 
  285. 3.加sp1后还能用的无边框窗口!!
  286. <HTML XMLNS:IE> 
  287. <meta http-equiv="Content-Type" content="text/html; charset=gb2312"
  288. <IE:Download ID="include" STYLE="behavior:url(#default#download)" /> 
  289. <title>Chromeless Window</title> 
  290. <SCRIPT LANGUAGE="JScript"
  291. /*--- Special Thanks For andot ---*/ 
  292. /* 
  293.  This following code are designed and writen by Windy_sk <seasonx@163.net> 
  294.  You can use it freely, but u must held all the copyright items! 
  295. */ 
  296. /*--- Thanks For andot Again ---*/ 
  297. var CW_width= 400; 
  298. var CW_height= 300; 
  299. var CW_top= 100; 
  300. var CW_left= 100; 
  301. var CW_url= "/"
  302. var New_CW= window.createPopup(); 
  303. var CW_Body= New_CW.document.body; 
  304. var content= ""
  305. var Csstext= "margin:1px;color:black; border:2px outset;border-style:expression(onmouseout=onmouseup=function(){this.style.borderStyle='outset'}, onmousedown=function(){if(event.button!=2)this.style.borderStyle='inset'});background-color:buttonface;width:16px;height:14px;font-size:12px;line-height:11px;cursor:Default;"
  306. //Build Window
  307. include.startDownload(CW_url, function(source){content=source}); 
  308. function insert_content(){ 
  309. var temp = ""
  310. CW_Body.style.overflow= "hidden"
  311. CW_Body.style.backgroundColor= "white"
  312. CW_Body.style.border=  "solid black 1px"
  313. content = content.replace(/<a ([^>]*)>/g,"<a onclick='parent.open(this.href);return false' $1>"); 
  314. temp += "<table width=100% height=100% cellpadding=0 cellspacing=0 border=0>"
  315. temp += "<tr style=';font-size:12px;background:#0099CC;height:20;cursor:default' ondblclick=/"Max.innerText=Max.innerText=='1'?'2':'1';parent.if_max=!parent.if_max;parent.show_CW();/" onmouseup='parent.drag_up(event)' onmousemove='parent.drag_move(event)' onmousedown='parent.drag_down(event)' onselectstart='return false' oncontextmenu='return false'>"
  316. temp += "<td style='color:#ffffff;padding-left:5px'>Chromeless Window For IE6 SP1</td>"
  317. temp += "<td style='color:#ffffff;padding-right:5px;' align=right>"
  318. temp += "<span id=Help  onclick=/"alert('Chromeless Window For IE6 SP1  -  Ver 1.0//n//nCode By Windy_sk//n//nSpecial Thanks For andot')/" style=/""+CSStext+"font-family:System;padding-right:2px;/">?</span>"
  319. temp += "<span id=Min   onclick='parent.New_CW.hide();parent.blur()' style=/""+CSStext+"font-family:Webdings;/" title='Minimum'>0</span>"
  320. temp += "<span id=Max   onclick=/"this.innerText=this.innerText=='1'?'2':'1';parent.if_max=!parent.if_max;parent.show_CW();/" style=/""+CSStext+"font-family:Webdings;/" title='Maximum'>1</span>"
  321. temp += "<span id=Close onclick='parent.opener=null;parent.close()' style=/""+CSStext+"font-family:System;padding-right:2px;/" title='Close'>x</span>"
  322. temp += "</td></tr><tr><td colspan=2>"
  323. temp += "<div id=include style='overflow:scroll;overflow-x:hidden;overflow-y:auto; HEIGHT: 100%; width:"+CW_width+"'>"
  324. temp += content; 
  325. temp += "</div>"
  326. temp += "</td></tr></table>"
  327. CW_Body.innerHTML = temp; 
  328. setTimeout("insert_content()",1000); 
  329. var if_max = true
  330. function show_CW(){ 
  331. window.moveTo(10000, 10000); 
  332. if(if_max){ 
  333. New_CW.show(CW_top, CW_left, CW_width, CW_height); 
  334. if(typeof(New_CW.document.all.include)!="undefined"){ 
  335. New_CW.document.all.include.style.width = CW_width; 
  336. New_CW.document.all.Max.innerText = "1"
  337. }else
  338. New_CW.show(0, 0, screen.width, screen.height); 
  339. New_CW.document.all.include.style.width = screen.width; 
  340. window.onfocus  = show_CW;
  341. window.onresize = show_CW; 
  342. // Move Window 
  343. var drag_x,drag_y,draging=false 
  344. function drag_move(e){ 
  345. if (draging){ 
  346. New_CW.show(e.screenX-drag_x, e.screenY-drag_y, CW_width, CW_height); 
  347. return false
  348. function drag_down(e){ 
  349. if(e.button==2)return
  350. if(New_CW.document.body.offsetWidth==screen.width && New_CW.document.body.offsetHeight==screen.height)return
  351. drag_x=e.clientX; 
  352. drag_y=e.clientY; 
  353. draging=true
  354. e.srcElement.setCapture(); 
  355. function drag_up(e){ 
  356. draging=false
  357. e.srcElement.releaseCapture(); 
  358. if(New_CW.document.body.offsetWidth==screen.width && New_CW.document.body.offsetHeight==screen.height) return
  359. CW_top  = e.screenX-drag_x; 
  360. CW_left = e.screenY-drag_y; 
  361. </SCRIPT>
  362. </HTML> 
  363. 贴两个关于treeview的 
  364.   <script language="javascript"
  365. <!-- 
  366. //初始化选中节点 
  367. function initchecknode() 
  368.  var node=TreeView1.getTreeNode("1"); 
  369.  node.setAttribute("Checked","true"); 
  370.  setcheck(node,"true"); 
  371.  FindCheckedFromNode(TreeView1); 
  372. //oncheck事件 
  373. function tree_oncheck(tree) 
  374.  var node=tree.getTreeNode(tree.clickedNodeIndex); 
  375.  var Pchecked=tree.getTreeNode(tree.clickedNodeIndex).getAttribute("checked"); 
  376.  setcheck(node,Pchecked); 
  377.  document.all.checked.value=""
  378.  document.all.unchecked.value=""
  379.  FindCheckedFromNode(TreeView1); 
  380. //设置子节点选中 
  381. function setcheck(node,Pc) 
  382.  var i; 
  383.  var ChildNode=new Array(); 
  384.  ChildNode=node.getChildren(); 
  385.   
  386.  if(parseInt(ChildNode.length)==0) 
  387.   return
  388.  else 
  389.  { 
  390.   for(i=0;i<ChildNode.length;i++) 
  391.   { 
  392.    var cNode; 
  393.    cNode=ChildNode[i]; 
  394.    if(parseInt(cNode.getChildren().length)!=0) 
  395.     setcheck(cNode,Pc); 
  396.    cNode.setAttribute("Checked",Pc); 
  397.   } 
  398.  } 
  399. //获取所有节点状态 
  400. function FindCheckedFromNode(node) { 
  401.  var i = 0; 
  402.  var nodes = new Array(); 
  403.  nodes = node.getChildren(); 
  404.   
  405.  for (i = 0; i < nodes.length; i++) { 
  406.   var cNode; 
  407.   cNode=nodes[i]; 
  408.   if (cNode.getAttribute("Checked")) 
  409.    AddChecked(cNode);
  410. else 
  411.       AddUnChecked(cNode); 
  412.   
  413.   if (parseInt(cNode.getChildren().length) != 0 ) { 
  414.    FindCheckedFromNode(cNode); 
  415.   } 
  416.  } 
  417. //添加选中节点 
  418. function AddChecked(node) { 
  419.  document.all.checked.value += node.getAttribute("NodeData"); 
  420.  document.all.checked.value += ','
  421. //添加未选中节点 
  422. function AddUnChecked(node) { 
  423.  document.all.unchecked.value += node.getAttribute("NodeData"); 
  424.  document.all.unchecked.value += ','
  425. //--> 
  426.   </script> 
  427. treeview中如何在服务器端得到客户端设置后的节点选中状态 
  428.  <script language="C#" runat="server"
  429.    private void Button1_Click(object sender, System.EventArgs e) 
  430.    { 
  431.     Response.Write(TreeView1.Nodes[0].Checked); 
  432.    } 
  433.   </script> 
  434.   <script language="javascript"
  435.    function set_check() 
  436.    { 
  437.     var nodeindex = "0"
  438.     var node=TreeView1.getTreeNode(nodeindex); 
  439.     node.setAttribute("Checked","True"); 
  440.     TreeView1.queueEvent('oncheck', nodeindex); 
  441.    } 
  442.   </script> 
  443. 三個實用的小技巧:關閉輸入法.禁止貼上.禁止複製 
  444. 關閉輸入法 
  445. 本文字框輸入法被關閉:  
  446. 語法: style="ime-mode:disabled" 
  447. 範例: <input type="text" name="textfield" style="ime-mode:disabled"
  448. 禁止貼上 
  449. 本文字框禁止貼上文字:  
  450. 語法:onpaste="return false" 
  451. 範例:<input type="text" name="textfield" onpaste="return false"
  452. 禁止複製 
  453. 本文字框禁止複製:  
  454. 語法:oncopy="return false;" oncut="return false;" 
  455. 範例:<input name="textfield" type="text" value="不能複製裡面的字" oncopy="return false;" oncut="return false;"
  456. //================================ 
  457. //Cookie操作 
  458. //================================ 
  459. function getCookieVal (offset) 
  460. var endstr = document.cookie.indexOf (";", offset); 
  461. if (endstr == -1) 
  462. endstr = document.cookie.length; 
  463. return unescape(document.cookie.substring(offset, endstr)); 
  464. function GetCookie (name) 
  465. var arg = name + "="
  466. var alen = arg.length; 
  467. var clen = document.cookie.length; 
  468. var i = 0; 
  469. while (i < clen) 
  470. var j = i + alen; 
  471. if (document.cookie.substring(i, j) == arg) 
  472. return getCookieVal (j); 
  473. i = document.cookie.indexOf(" ", i) + 1; 
  474. if (i == 0) 
  475. break
  476. return null
  477. function deleteCookie(cname) { 
  478.   var expdate = new Date(); 
  479.   expdate.setTime(expdate.getTime() - (24 * 60 * 60 * 1000 * 369)); 
  480.  // document.cookie =" ckValue="ok"; expires="+ expdate.toGMTString();
  481. setCookie(cname,"",expdate); 
  482. function setCookie (name, value, expires) { 
  483.   document.cookie = name + "=" + escape(value) + 
  484.     "; expires=" + expires.toGMTString() ; 
  485. 一个可以在页面上随意画线、多边形、圆,填充等功能的js  (part 1) 
  486. var jg_ihtm, jg_ie, jg_fast, jg_dom, jg_moz, 
  487. jg_n4 = (document.layers && typeof document.classes != "undefined"); 
  488. function chkDHTM(x, i) 
  489. x = document.body null
  490. jg_ie = x && typeof x.insertAdjacentHTML != "undefined"
  491. jg_dom = (x && !jg_ie && 
  492. typeof x.appendChild != "undefined" && 
  493. typeof document.createRange != "undefined" && 
  494. typeof (i = document.createRange()).setStartBefore != "undefined" && 
  495. typeof i.createContextualFragment != "undefined"); 
  496. jg_ihtm = !jg_ie && !jg_dom && x && typeof x.innerHTML != "undefined"
  497. jg_fast = jg_ie && document.all && !window.opera; 
  498. jg_moz = jg_dom && typeof x.style.MozOpacity != "undefined"
  499. function pntDoc() 
  500. this.wnd.document.write(jg_fast? this.htmRpc() : this.htm); 
  501. this.htm = ''
  502. function pntCnvDom() 
  503. var x = document.createRange(); 
  504. x.setStartBefore(this.cnv); 
  505. x = x.createContextualFragment(jg_fast? this.htmRpc() : this.htm); 
  506. this.cnv.appendChild(x); 
  507. this.htm = ''
  508. function pntCnvIe() 
  509. this.cnv.insertAdjacentHTML("BeforeEnd", jg_fast? this.htmRpc() : this.htm);
  510. this.htm = ''
  511. function pntCnvIhtm() 
  512. this.cnv.innerHTML += this.htm; 
  513. this.htm = ''
  514. function pntCnv() 
  515. this.htm = ''
  516. function mkDiv(x, y, w, h) 
  517. t
【上篇】
【下篇】

抱歉!评论已关闭.