找回密码
 注册
【阿里云】2核2G云新老同享 99元/年,续费同价华为云精选云产品特惠做网站就用糖果主机Jtti,新加坡服务器,美国服务器,香港服务器
查看: 780|回复: 13

太值得收藏了!!

[复制链接]
发表于 2005 年 5 月 26 日 23:46:58 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

×
  表单相关收集

只能是写限定的东西
-----------------------------------------------------------------------------------
ENTER键可以让光标移到下一个输入框
<input onkeydown="if(event.keyCode==13)event.keyCode=9" >

只能是中文<input onkeyup="value=value.replace(/[ -~]/g,'')" onkeydown="if(event.keyCode==13)event.keyCode=9">

只能是英文和数字.屏蔽了输入法<input style="ime-mode:disabled" onkeydown="if(event.keyCode==13)event.keyCode=9">

只能输入英文和数字<input onkeyup="value=value.replace(/[\W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" onkeydown="if(event.keyCode==13)event.keyCode=9">
只能是数字<input onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
只能显示,不能修改的文本框<input readOnly value="只能显示,不能修改">
-----------------------------------------------------------------------------------

只能是数字,判断按键
-----------------------------------------------------------------------------------

<script  language=javascript>
function  onlyNum()
{
if(!((event.keyCode>=48&&event.keyCode<=57)||(event.keyCode>=96&&event.keyCode<=105)||(event.keyCode==8)))
event.returnValue=false;
}
</script>
<input  onkeydown="onlyNum();">  
-----------------------------------------------------------------------------------


附:获取键盘的KeyCode
-----------------------------------------------------------------------------------
<html>
<head>
<script language="javascript">
  ns4 = (document.layers) ? True : false;
  ie4 = (document.all) ? True : false;
function keyDown(e){
  if(ns4){
  var nkey=e.which;
  var iekey='现在是ns浏览器';
  var realkey=String.fromCharCode(e.which);
}
  if(ie4){
  var iekey=event.keyCode;
  var nkey='现在是ie浏览器';
  var realkey=String.fromCharCode(event.keyCode);
  if(event.keyCode==32){realkey='\' 空格\''}
  if(event.keyCode==13){realkey='\' 回车\''}
  if(event.keyCode==27){realkey='\' Esc\''}
  if(event.keyCode==16){realkey='\' Shift\''}
  if(event.keyCode==17){realkey='\' Ctrl\''}
  if(event.keyCode==18){realkey='\' Alt\''}
}
  alert('ns浏览器中键值:'+nkey+'\n'+'ie浏览器中键值:'+iekey+'\n'+'实际键为'+realkey);
}
document.onkeydown = keyDown;
if(ns4){
document.captureEvents(Event.KEYDOWN);}
</script>
</head>
<body>
//Javascript Document.
<hr>
<center>
<h3>请按任意一个键。。。。</h3>
</center>
</body>
</html>
-----------------------------------------------------------------------------------


限制网页用键盘
-----------------------------------------------------------------------------------
<body onkeydown="alert('禁用');return false;">
限制键盘的某个键:body onkeydown="if(event.keyCode==num){alert('禁用');return false;}
-----------------------------------------------------------------------------------


再加个找按键的值
-----------------------------------------------------------------------------------
<script>
function show(){
  alert("ASCII代码是:"+event.keyCode);
}
</script>
<body onkeydown="show()">
-----------------------------------------------------------------------------------

只能是IP地址
-----------------------------------------------------------------------------------<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name=&quotrogId" content="FrontPage.Editor.Document">
<style>
.a3{width:30;border:0;text-align:center}
</style>
<script>
function mask(obj){
obj.value=obj.value.replace(/[^\d]/g,'')
key1=event.keyCode
if (key1==37 || key1==39)
{ obj.blur();
nextip=parseInt(obj.name.substr(2,1))
nextip=key1==37?nextip-1:nextip+1;
nextip=nextip>=5?1:nextip
nextip=nextip<=0?4:nextip
eval("ip"+nextip+".focus()")
}
if(obj.value.length>=3)
if(parseInt(obj.value)>=256 || parseInt(obj.value)<=0)
{
alert(parseInt(obj.value)+"IP地址错误!")
obj.value=""
obj.focus()
return false;
}
else
{ obj.blur();
nextip=parseInt(obj.name.substr(2,1))+1
nextip=nextip>=5?1:nextip
nextip=nextip<=0?4:nextip
eval("ip"+nextip+".focus()")
}
}
function mask_c(obj)
{
clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))
}
</script>

<title>IP地址输入</title>
</head>
<body>IP地址输入
<div style="border-width:1;border-color:balck;border-style:solid;width:165;font-size:9pt">
<input type=text name=ip1 maxlength=3 class=a3 onkeyup="mask(this)" onbeforepaste=mask_c()>.
<input type=text name=ip2 maxlength=3 class=a3 onkeyup="mask(this)" onbeforepaste=mask_c()>.
<input type=text name=ip3 maxlength=3 class=a3 onkeyup="mask(this)" onbeforepaste=mask_c()>.
<input type=text name=ip4 maxlength=3 class=a3 onkeyup="mask(this)" onbeforepaste=mask_c()>
</div>
</body>
</html>
-----------------------------------------------------------------------------------

用#default#savehistory防止后退清空text文本框
-----------------------------------------------------------------------------------
<HTML>
<HEAD>
<META NAME="save" CONTENT="history">
<STYLE>
  .saveHistory {behavior:url(#default#savehistory);}
</STYLE>
</HEAD>
<BODY>
<INPUT class=saveHistory type=text id=oPersistInput>
<input type=button onclick='javascript:location.href="<a target='_blank' href='http://www.cnbruce.com/red/"''>http://www.cnbruce.com/red/"'</a> value='点击进入,再按后退键试试?'>
</BODY>
</HTML>
-----------------------------------------------------------------------------------

TEXTAREA自适应文字行数的多少
-----------------------------------------------------------------------------------
<textarea rows=1 name=s1 cols=27 onpropertychange="this.style.posHeight=this.scrollHeight">
-----------------------------------------------------------------------------------
上传预览图片
-----------------------------------------------------------------------------------
<img id=pic  src=http://www.cnbruce.com/images/logo.gif>
<input type=file name=file><input type=button onclick=pic.src=file.value value=预览图片>
<input type=button onclick=alert(file.value) value=图片地址>
<input type=button onclick="file.outerHTML=file.outerHTML.replace(/value=\w/g,'')" value="清除file里字">
-----------------------------------------------------------------------------------

去掉下拉选项的边框
-----------------------------------------------------------------------------------

<div style="position: absolute; left: 10px; top: 10px; width: 115px; height: 20px;  clip:rect(2 114 20 2);">
  <select>
   <option >cnpeople</option>
   <option >cnrose</option>
  <option >cnbruce</option>  
  </select>
  </font>
</div>
-----------------------------------------------------------------------------------

下拉列表打开窗口
-----------------------------------------------------------------------------------
<select  onChange="if(this.selectedIndex && this.selectedIndex!=0){window.open(this.value);}this.selectedIndex=0;">
<option selected>更多链接……</option>
<option value="<a target='_blank' href='http://www.windsn.com">windsn.com</option>'>http://www.windsn.com">windsn.com</option></a>
<option value="<a target='_blank' href='http://www.yaguo.com/~mswenlin">yaguo/~mswenlin</option>'>http://www.yaguo.com/~mswenlin">yaguo/~mswenlin</option></a>
<option value="<a target='_blank' href='http://www.blueidea.com">blue!dea'>http://www.blueidea.com">blue!dea</a>
</select>
-----------------------------------------------------------------------------------

TAB的显示
-----------------------------------------------------------------------------------
<script>
function editTab()
{
   var code, sel, tmp, r
   var tabs=""
   event.returnValue = false
   sel =event.srcElement.document.selection.createRange()
   r = event.srcElement.createTextRange()

   switch (event.keyCode)
   {
       case (8)    :
           if (!(sel.getClientRects().length > 1))
           {
               event.returnValue = true
               return
           }
           code = sel.text
           tmp = sel.duplicate()
           tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top)
           sel.setEndPoint("startToStart", tmp)
           sel.text = sel.text.replace(/^\t/gm, "")
           code = code.replace(/^\t/gm, "").replace(/\r\n/g, "\r")
           r.findText(code)
           r.select()
           break
       case (9)    :
           if (sel.getClientRects().length > 1)
           {
               code = sel.text
               tmp = sel.duplicate()
               tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top)
               sel.setEndPoint("startToStart", tmp)
               sel.text = "\t"+sel.text.replace(/\r\n/g, "\r\t")
               code = code.replace(/\r\n/g, "\r\t")
               r.findText(code)
               r.select()
           }
           else
           {
               sel.text = "\t"
               sel.select()
           }
           break
       case (13)    :
           tmp = sel.duplicate()
           tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top)
           tmp.setEndPoint("endToEnd", sel)

           for (var I=0; tmp.text.match(/^[\t]+/g) && I<tmp.text.match(/^[\t]+/g)[0].length; I++)    tabs += "\t"
           sel.text = "\r\n"+tabs
           sel.select()
           break
       default        :
           event.returnValue = true
           break
   }
}
</script>

<textarea  cols=75  rows=20  onkeydown="editTab()">
<script>
alert("ok")
</script>
</textarea>
-----------------------------------------------------------------------------------

文本框的上/下拉
-----------------------------------------------------------------------------------
<form name="cnbruce">
<textarea name="com">
</textarea>
</form>
<SPAN title='放大输入框' style='FONT-SIZE: 12px; CURSOR: hand'  onclick=document.cnbruce.com.rows+=4>向下</SPAN>
<SPAN title='缩小输入框' style='FONT-SIZE: 12px; CURSOR: hand' class='arrow' onclick='if(document.cnbruce.com.rows>=4)document.cnbruce.com.rows-=4;else return false'>向上</SPAN>
-----------------------------------------------------------------------------------


一个复选框,点击之后一组复选框全部都选上
-----------------------------------------------------------------------------------
<input type="checkbox" name="checkA" onpropertychange="for(I=0;I<A.children.length;I++){A.children[=I].checked=this.checked}">a

<span id="A">
<input type="checkbox" name="A1">
<input type="checkbox" name="A2">
<input type="checkbox" name="A3">
</span>
-----------------------------------------------------------------------------------

Debug Textarea:在线写 js 脚本的时候,用来即时查错的东西!
-----------------------------------------------------------------------------------
<HTML>
<HEAD>
<TITLE>Debug Textarea</TITLE>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
</HEAD>
<style>
* {
   font-size: 12px
}
body {
   margin: 10px; padding: 0px
}
table.list{
   cursor: default;
   border:1px solid #cccccc
   background-color: #cccccc;
   border-collapse: collapse;
   border-Color: #cccccc;
}
</style>
<script language="javascript">
// Coded by windy_sk <windy_sk@126.com> 20040205

function reportError(msg,url,line) {
   var str = "You have found an error as below: \n\n";
   str += "Err: " + msg + " on line: " + line;
   alert(str);
   return true;
}

window.onerror = reportError;
document.onkeydown = function() {
   if(event.ctrlKey){
       switch(event.keyCode) {
           case 82: //r
               runcode();
               break;
           case 83: //s
               savecode();
               break;
           case 71: //g
               goto(prompt(&#39lease input the line number', '1'));
               break;
           case 65: //a
               document.execCommand("selectAll");
               break;
           case 67: //c
               document.execCommand("Copy");
               break;
           case 88: //x
               document.execCommand("Cut");
               break;
           case 86: //v
               document.execCommand(&quotaste");
               break;
           case 90: //z
               document.execCommand("Undo");
               break;
           case 89: //y
               document.execCommand("Redo");
               break;
           default:
               break;
       }
       event.keyCode = 0;
       event.returnValue = false;
   }
   return;
}


function show_ln(){
   var txt_ln     = document.getElementById('txt_ln');
   var txt_main     = document.getElementById('txt_main');
   txt_ln.scrollTop = txt_main.scrollTop;
   while(txt_ln.scrollTop != txt_main.scrollTop) {
       txt_ln.value += (I++) + '\n';
       txt_ln.scrollTop = txt_main.scrollTop;
   }
   return;
}


function editTab(){
   var code, sel, tmp, r
   var tabs=''
   event.returnValue = false
   sel =event.srcElement.document.selection.createRange()
   r = event.srcElement.createTextRange()

   switch (event.keyCode){
       case (8)    :
           if (!(sel.getClientRects().length > 1)){
               event.returnValue = true
               return
           }
           code = sel.text
           tmp = sel.duplicate()
           tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top)
           // 出错检验代码~~~~~~
           if(sel.parentElement() != tmp.parentElement()) return;
           sel.setEndPoint('startToStart', tmp)
           sel.text = sel.text.replace(/^\t/gm, '')
           code = code.replace(/^\t/gm, '').replace(/\r\n/g, '\r')
           r.findText(code)
           r.select()
           break
       case (9)    :
           if (sel.getClientRects().length > 1){
               code = sel.text
               tmp = sel.duplicate()
               tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top)
               // 出错检验代码~~~~~~
               if(sel.parentElement() != tmp.parentElement()) return;
               sel.setEndPoint('startToStart', tmp)
               sel.text = '\t'+sel.text.replace(/\r\n/g, '\r\t')
               code = code.replace(/\r\n/g, '\r\t')
               r.findText(code)
               r.select()
           }else{
               sel.text = '\t'
               sel.select()
           }
           break
       case (13)    :
           tmp = sel.duplicate()
           tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top)
           // 出错检验代码~~~~~~
           if(sel.parentElement() != tmp.parentElement()) return;
           tmp.setEndPoint('endToEnd', sel)
           for (var I=0; tmp.text.match(/^[\t]+/g) && I<tmp.text.match(/^[\t]+/g)[0].length; I++)    tabs += '\t'
           sel.text = '\r\n'+tabs
           sel.select()
           break
       default        :
           event.returnValue = true
           break;
   }
   return;
}


function runcode() {
   var str = document.getElementById("txt_main").value;
   var code_win = window.open('about:blank');
   code_win.document.open();
   code_win.document.writeln("<script>");
   code_win.document.writeln("function reportError(msg,url,line){\nline-=14;\nvar str='You have found an error as below: \\n\\n';\nstr+='Err: '+msg+' on line: '+(line);\nalert(str);\nopener.goto(line);\nopener.focus();\nwindow.onerror=null;\nsetTimeout('self.close()',10);\nreturn true;\n}");
   code_win.document.writeln("window.onerror = reportError;");
   code_win.document.writeln("<\/script>");
   code_win.document.writeln(str);
   code_win.document.close();
   return;
}


function savecode() {
   var str = document.getElementById("txt_main").value;
   var code_win = window.open('about:blank','_blank','top=10000');
   code_win.document.open();
   code_win.document.writeln(str);
   code_win.document.close();
   code_win.document.execCommand('saveas','','code.html');
   code_win.close();
   return;
}


function goto(ln) {
   if(!/^\d+$/.test(ln)) return;
   var obj = document.getElementById("txt_main");
   var rng = obj.createTextRange();
   var arr = obj.value.replace(/\r/, "").split(/\n/);
   if(ln>arr.length) ln = arr.length;
   var str_tmp = "";
   for(var I=0; I<ln-1; I++) {
       str_tmp += arr[=I];
   }
   rng.moveStart('character',str_tmp.length+1);
   str_tmp = "";
   for(I=ln; I<arr.length; I++) {
       str_tmp += arr[=I];
   }
   rng.moveEnd('character',-str_tmp.length);
   rng.select();
   return;
}

window.onload = function() {document.getElementById("txt_main").value = "<script>\nalert(')\n<\/script>";}
</script>
<BODY>
<table width='600' class='list' border='1' bgcolor='#eeeeee' bordercolorlight='#000000' bordercolordark='#FFFFFF' cellpadding='0' cellspacing='0'>
  <tr bgcolor='#cccccc'>
   <td colspan='2' height='20' align='center'><b>Debug Textarea</b></td>
  </tr>
  <tr>
   <td colspan='2'>
       <table width='95%' border='0' align='center' >
     <tr>
       <td align='center'>
         <textarea id='txt_ln' name='content' rows='10' style='width:40px;overflow:hidden;height:200px;border-right:0px;text-align:right;line-height:14px' onselectstart='this.nextSibling.focus();return false' readonly></textarea><textarea id='txt_main' name='content' rows='10' cols='80' onkeydown='editTab()' onkeyup='show_ln()' onscroll='show_ln()' wrap='off' style='overflow:auto;height:200px;padding-left:5px;border-left:0px;line-height:14px'></textarea>
         <script>for(var I=1; I<=20; I++) document.getElementById('txt_ln').value += I + '\n';</script>
       </td>
     </tr>
         <tr>
           <td align='center'>
             <input type='button' value=' 运 行 ' onclick='runcode()' accesskey='r'>  
             <input type='button' value=' 保 存 ' onclick='savecode()' accesskey='s'>  
             <input type='button' value=' 跳 转 ' onclick="goto(prompt('Please input the line number', '1'))"  accesskey='g'>  
           </td>
         </tr>
       </table>
   </td>
  </tr>
</table>
</BODY>
</HTML>
-----------------------------------------------------------------------------------
TAB键在文本域中的体现
-----------------------------------------------------------------------------------
<script>
function editTab()
{
   var code, sel, tmp, r
   var tabs=""
   event.returnValue = false
   sel =event.srcElement.document.selection.createRange()
   r = event.srcElement.createTextRange()

   switch (event.keyCode)
   {
       case (8)    :
           if (!(sel.getClientRects().length > 1))
           {
               event.returnValue = true
               return
           }
           code = sel.text
           tmp = sel.duplicate()
           tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top)
           sel.setEndPoint("startToStart", tmp)
           sel.text = sel.text.replace(/^\t/gm, "")
           code = code.replace(/^\t/gm, "").replace(/\r\n/g, "\r")
           r.findText(code)
           r.select()
           break
       case (9)    :
           if (sel.getClientRects().length > 1)
           {
               code = sel.text
               tmp = sel.duplicate()
               tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top)
               sel.setEndPoint("startToStart", tmp)
               sel.text = "\t"+sel.text.replace(/\r\n/g, "\r\t")
               code = code.replace(/\r\n/g, "\r\t")
               r.findText(code)
               r.select()
           }
           else
           {
               sel.text = "\t"
               sel.select()
           }
           break
       case (13)    :
           tmp = sel.duplicate()
           tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top)
           tmp.setEndPoint("endToEnd", sel)

           for (var I=0; tmp.text.match(/^[\t]+/g) && I<tmp.text.match(/^[\t]+/g)[0].length; I++)    tabs += "\t"
           sel.text = "\r\n"+tabs
           sel.select()
           break
       default        :
           event.returnValue = true
           break
   }
}
</script>

<textarea cols=75 rows=20 onkeydown="editTab()">
<script>
alert("ok")
</script></textarea>

-----------------------------------------------------------------------------------
获取input的非value值,而是显示文本值
-----------------------------------------------------------------------------------
<select name="sss" onChange="alert(this.options[this.selectedIndex].text)">
<option value="1">asdf</option>
<option value="2">bbbb</option>
<option value="3">ccc</option>
</select>
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
发表于 2005 年 5 月 26 日 23:50:23 | 显示全部楼层
【腾讯云】2核2G云服务器新老同享 99元/年,续费同价
不错,收藏了。。
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2005 年 5 月 27 日 09:30:38 | 显示全部楼层
收藏了。。
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2005 年 5 月 27 日 09:43:36 | 显示全部楼层
学习中~
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2005 年 5 月 27 日 12:03:26 | 显示全部楼层
收下了
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2005 年 5 月 27 日 16:54:20 | 显示全部楼层
是呀 值得收藏
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2005 年 5 月 27 日 23:19:21 | 显示全部楼层
【腾讯云】2核2G云服务器新老同享 99元/年,续费同价
是什么代码?PHP或者ASP还是哪里都能用。
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2005 年 5 月 27 日 23:25:33 | 显示全部楼层
JavaScript,客户端脚本。
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2005 年 5 月 27 日 23:58:33 | 显示全部楼层
不错~
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

 楼主| 发表于 2005 年 5 月 26 日 23:46:58 | 显示全部楼层

太值得收藏了!!

  表单相关收集

只能是写限定的东西
-----------------------------------------------------------------------------------
ENTER键可以让光标移到下一个输入框
<input onkeydown="if(event.keyCode==13)event.keyCode=9" >

只能是中文<input onkeyup="value=value.replace(/[ -~]/g,'')" onkeydown="if(event.keyCode==13)event.keyCode=9">

只能是英文和数字.屏蔽了输入法<input style="ime-mode:disabled" onkeydown="if(event.keyCode==13)event.keyCode=9">

只能输入英文和数字<input onkeyup="value=value.replace(/[\W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" onkeydown="if(event.keyCode==13)event.keyCode=9">
只能是数字<input onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
只能显示,不能修改的文本框<input readOnly value="只能显示,不能修改">
-----------------------------------------------------------------------------------

只能是数字,判断按键
-----------------------------------------------------------------------------------

<script  language=javascript>
function  onlyNum()
{
if(!((event.keyCode>=48&&event.keyCode<=57)||(event.keyCode>=96&&event.keyCode<=105)||(event.keyCode==8)))
event.returnValue=false;
}
</script>
<input  onkeydown="onlyNum();">  
-----------------------------------------------------------------------------------


附:获取键盘的KeyCode
-----------------------------------------------------------------------------------
<html>
<head>
<script language="javascript">
  ns4 = (document.layers) ? True : false;
  ie4 = (document.all) ? True : false;
function keyDown(e){
  if(ns4){
  var nkey=e.which;
  var iekey='现在是ns浏览器';
  var realkey=String.fromCharCode(e.which);
}
  if(ie4){
  var iekey=event.keyCode;
  var nkey='现在是ie浏览器';
  var realkey=String.fromCharCode(event.keyCode);
  if(event.keyCode==32){realkey='\' 空格\''}
  if(event.keyCode==13){realkey='\' 回车\''}
  if(event.keyCode==27){realkey='\' Esc\''}
  if(event.keyCode==16){realkey='\' Shift\''}
  if(event.keyCode==17){realkey='\' Ctrl\''}
  if(event.keyCode==18){realkey='\' Alt\''}
}
  alert('ns浏览器中键值:'+nkey+'\n'+'ie浏览器中键值:'+iekey+'\n'+'实际键为'+realkey);
}
document.onkeydown = keyDown;
if(ns4){
document.captureEvents(Event.KEYDOWN);}
</script>
</head>
<body>
//Javascript Document.
<hr>
<center>
<h3>请按任意一个键。。。。</h3>
</center>
</body>
</html>
-----------------------------------------------------------------------------------


限制网页用键盘
-----------------------------------------------------------------------------------
<body onkeydown="alert('禁用');return false;">
限制键盘的某个键:body onkeydown="if(event.keyCode==num){alert('禁用');return false;}
-----------------------------------------------------------------------------------


再加个找按键的值
-----------------------------------------------------------------------------------
<script>
function show(){
  alert("ASCII代码是:"+event.keyCode);
}
</script>
<body onkeydown="show()">
-----------------------------------------------------------------------------------

只能是IP地址
-----------------------------------------------------------------------------------<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name=&quotrogId" content="FrontPage.Editor.Document">
<style>
.a3{width:30;border:0;text-align:center}
</style>
<script>
function mask(obj){
obj.value=obj.value.replace(/[^\d]/g,'')
key1=event.keyCode
if (key1==37 || key1==39)
{ obj.blur();
nextip=parseInt(obj.name.substr(2,1))
nextip=key1==37?nextip-1:nextip+1;
nextip=nextip>=5?1:nextip
nextip=nextip<=0?4:nextip
eval("ip"+nextip+".focus()")
}
if(obj.value.length>=3)
if(parseInt(obj.value)>=256 || parseInt(obj.value)<=0)
{
alert(parseInt(obj.value)+"IP地址错误!")
obj.value=""
obj.focus()
return false;
}
else
{ obj.blur();
nextip=parseInt(obj.name.substr(2,1))+1
nextip=nextip>=5?1:nextip
nextip=nextip<=0?4:nextip
eval("ip"+nextip+".focus()")
}
}
function mask_c(obj)
{
clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))
}
</script>

<title>IP地址输入</title>
</head>
<body>IP地址输入
<div style="border-width:1;border-color:balck;border-style:solid;width:165;font-size:9pt">
<input type=text name=ip1 maxlength=3 class=a3 onkeyup="mask(this)" onbeforepaste=mask_c()>.
<input type=text name=ip2 maxlength=3 class=a3 onkeyup="mask(this)" onbeforepaste=mask_c()>.
<input type=text name=ip3 maxlength=3 class=a3 onkeyup="mask(this)" onbeforepaste=mask_c()>.
<input type=text name=ip4 maxlength=3 class=a3 onkeyup="mask(this)" onbeforepaste=mask_c()>
</div>
</body>
</html>
-----------------------------------------------------------------------------------

用#default#savehistory防止后退清空text文本框
-----------------------------------------------------------------------------------
<HTML>
<HEAD>
<META NAME="save" CONTENT="history">
<STYLE>
  .saveHistory {behavior:url(#default#savehistory);}
</STYLE>
</HEAD>
<BODY>
<INPUT class=saveHistory type=text id=oPersistInput>
<input type=button onclick='javascript:location.href="<a target='_blank' href='http://www.cnbruce.com/red/"''>http://www.cnbruce.com/red/"'</a> value='点击进入,再按后退键试试?'>
</BODY>
</HTML>
-----------------------------------------------------------------------------------

TEXTAREA自适应文字行数的多少
-----------------------------------------------------------------------------------
<textarea rows=1 name=s1 cols=27 onpropertychange="this.style.posHeight=this.scrollHeight">
-----------------------------------------------------------------------------------
上传预览图片
-----------------------------------------------------------------------------------
<img id=pic  src=http://www.cnbruce.com/images/logo.gif>
<input type=file name=file><input type=button onclick=pic.src=file.value value=预览图片>
<input type=button onclick=alert(file.value) value=图片地址>
<input type=button onclick="file.outerHTML=file.outerHTML.replace(/value=\w/g,'')" value="清除file里字">
-----------------------------------------------------------------------------------

去掉下拉选项的边框
-----------------------------------------------------------------------------------

<div style="position: absolute; left: 10px; top: 10px; width: 115px; height: 20px;  clip:rect(2 114 20 2);">
  <select>
   <option >cnpeople</option>
   <option >cnrose</option>
  <option >cnbruce</option>  
  </select>
  </font>
</div>
-----------------------------------------------------------------------------------

下拉列表打开窗口
-----------------------------------------------------------------------------------
<select  onChange="if(this.selectedIndex && this.selectedIndex!=0){window.open(this.value);}this.selectedIndex=0;">
<option selected>更多链接……</option>
<option value="<a target='_blank' href='http://www.windsn.com">windsn.com</option>'>http://www.windsn.com">windsn.com</option></a>
<option value="<a target='_blank' href='http://www.yaguo.com/~mswenlin">yaguo/~mswenlin</option>'>http://www.yaguo.com/~mswenlin">yaguo/~mswenlin</option></a>
<option value="<a target='_blank' href='http://www.blueidea.com">blue!dea'>http://www.blueidea.com">blue!dea</a>
</select>
-----------------------------------------------------------------------------------

TAB的显示
-----------------------------------------------------------------------------------
<script>
function editTab()
{
   var code, sel, tmp, r
   var tabs=""
   event.returnValue = false
   sel =event.srcElement.document.selection.createRange()
   r = event.srcElement.createTextRange()

   switch (event.keyCode)
   {
       case (8)    :
           if (!(sel.getClientRects().length > 1))
           {
               event.returnValue = true
               return
           }
           code = sel.text
           tmp = sel.duplicate()
           tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top)
           sel.setEndPoint("startToStart", tmp)
           sel.text = sel.text.replace(/^\t/gm, "")
           code = code.replace(/^\t/gm, "").replace(/\r\n/g, "\r")
           r.findText(code)
           r.select()
           break
       case (9)    :
           if (sel.getClientRects().length > 1)
           {
               code = sel.text
               tmp = sel.duplicate()
               tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top)
               sel.setEndPoint("startToStart", tmp)
               sel.text = "\t"+sel.text.replace(/\r\n/g, "\r\t")
               code = code.replace(/\r\n/g, "\r\t")
               r.findText(code)
               r.select()
           }
           else
           {
               sel.text = "\t"
               sel.select()
           }
           break
       case (13)    :
           tmp = sel.duplicate()
           tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top)
           tmp.setEndPoint("endToEnd", sel)

           for (var I=0; tmp.text.match(/^[\t]+/g) && I<tmp.text.match(/^[\t]+/g)[0].length; I++)    tabs += "\t"
           sel.text = "\r\n"+tabs
           sel.select()
           break
       default        :
           event.returnValue = true
           break
   }
}
</script>

<textarea  cols=75  rows=20  onkeydown="editTab()">
<script>
alert("ok")
</script>
</textarea>
-----------------------------------------------------------------------------------

文本框的上/下拉
-----------------------------------------------------------------------------------
<form name="cnbruce">
<textarea name="com">
</textarea>
</form>
<SPAN title='放大输入框' style='FONT-SIZE: 12px; CURSOR: hand'  onclick=document.cnbruce.com.rows+=4>向下</SPAN>
<SPAN title='缩小输入框' style='FONT-SIZE: 12px; CURSOR: hand' class='arrow' onclick='if(document.cnbruce.com.rows>=4)document.cnbruce.com.rows-=4;else return false'>向上</SPAN>
-----------------------------------------------------------------------------------


一个复选框,点击之后一组复选框全部都选上
-----------------------------------------------------------------------------------
<input type="checkbox" name="checkA" onpropertychange="for(I=0;I<A.children.length;I++){A.children[=I].checked=this.checked}">a

<span id="A">
<input type="checkbox" name="A1">
<input type="checkbox" name="A2">
<input type="checkbox" name="A3">
</span>
-----------------------------------------------------------------------------------

Debug Textarea:在线写 js 脚本的时候,用来即时查错的东西!
-----------------------------------------------------------------------------------
<HTML>
<HEAD>
<TITLE>Debug Textarea</TITLE>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
</HEAD>
<style>
* {
   font-size: 12px
}
body {
   margin: 10px; padding: 0px
}
table.list{
   cursor: default;
   border:1px solid #cccccc
   background-color: #cccccc;
   border-collapse: collapse;
   border-Color: #cccccc;
}
</style>
<script language="javascript">
// Coded by windy_sk <windy_sk@126.com> 20040205

function reportError(msg,url,line) {
   var str = "You have found an error as below: \n\n";
   str += "Err: " + msg + " on line: " + line;
   alert(str);
   return true;
}

window.onerror = reportError;
document.onkeydown = function() {
   if(event.ctrlKey){
       switch(event.keyCode) {
           case 82: //r
               runcode();
               break;
           case 83: //s
               savecode();
               break;
           case 71: //g
               goto(prompt(&#39lease input the line number', '1'));
               break;
           case 65: //a
               document.execCommand("selectAll");
               break;
           case 67: //c
               document.execCommand("Copy");
               break;
           case 88: //x
               document.execCommand("Cut");
               break;
           case 86: //v
               document.execCommand(&quotaste");
               break;
           case 90: //z
               document.execCommand("Undo");
               break;
           case 89: //y
               document.execCommand("Redo");
               break;
           default:
               break;
       }
       event.keyCode = 0;
       event.returnValue = false;
   }
   return;
}


function show_ln(){
   var txt_ln     = document.getElementById('txt_ln');
   var txt_main     = document.getElementById('txt_main');
   txt_ln.scrollTop = txt_main.scrollTop;
   while(txt_ln.scrollTop != txt_main.scrollTop) {
       txt_ln.value += (I++) + '\n';
       txt_ln.scrollTop = txt_main.scrollTop;
   }
   return;
}


function editTab(){
   var code, sel, tmp, r
   var tabs=''
   event.returnValue = false
   sel =event.srcElement.document.selection.createRange()
   r = event.srcElement.createTextRange()

   switch (event.keyCode){
       case (8)    :
           if (!(sel.getClientRects().length > 1)){
               event.returnValue = true
               return
           }
           code = sel.text
           tmp = sel.duplicate()
           tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top)
           // 出错检验代码~~~~~~
           if(sel.parentElement() != tmp.parentElement()) return;
           sel.setEndPoint('startToStart', tmp)
           sel.text = sel.text.replace(/^\t/gm, '')
           code = code.replace(/^\t/gm, '').replace(/\r\n/g, '\r')
           r.findText(code)
           r.select()
           break
       case (9)    :
           if (sel.getClientRects().length > 1){
               code = sel.text
               tmp = sel.duplicate()
               tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top)
               // 出错检验代码~~~~~~
               if(sel.parentElement() != tmp.parentElement()) return;
               sel.setEndPoint('startToStart', tmp)
               sel.text = '\t'+sel.text.replace(/\r\n/g, '\r\t')
               code = code.replace(/\r\n/g, '\r\t')
               r.findText(code)
               r.select()
           }else{
               sel.text = '\t'
               sel.select()
           }
           break
       case (13)    :
           tmp = sel.duplicate()
           tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top)
           // 出错检验代码~~~~~~
           if(sel.parentElement() != tmp.parentElement()) return;
           tmp.setEndPoint('endToEnd', sel)
           for (var I=0; tmp.text.match(/^[\t]+/g) && I<tmp.text.match(/^[\t]+/g)[0].length; I++)    tabs += '\t'
           sel.text = '\r\n'+tabs
           sel.select()
           break
       default        :
           event.returnValue = true
           break;
   }
   return;
}


function runcode() {
   var str = document.getElementById("txt_main").value;
   var code_win = window.open('about:blank');
   code_win.document.open();
   code_win.document.writeln("<script>");
   code_win.document.writeln("function reportError(msg,url,line){\nline-=14;\nvar str='You have found an error as below: \\n\\n';\nstr+='Err: '+msg+' on line: '+(line);\nalert(str);\nopener.goto(line);\nopener.focus();\nwindow.onerror=null;\nsetTimeout('self.close()',10);\nreturn true;\n}");
   code_win.document.writeln("window.onerror = reportError;");
   code_win.document.writeln("<\/script>");
   code_win.document.writeln(str);
   code_win.document.close();
   return;
}


function savecode() {
   var str = document.getElementById("txt_main").value;
   var code_win = window.open('about:blank','_blank','top=10000');
   code_win.document.open();
   code_win.document.writeln(str);
   code_win.document.close();
   code_win.document.execCommand('saveas','','code.html');
   code_win.close();
   return;
}


function goto(ln) {
   if(!/^\d+$/.test(ln)) return;
   var obj = document.getElementById("txt_main");
   var rng = obj.createTextRange();
   var arr = obj.value.replace(/\r/, "").split(/\n/);
   if(ln>arr.length) ln = arr.length;
   var str_tmp = "";
   for(var I=0; I<ln-1; I++) {
       str_tmp += arr[=I];
   }
   rng.moveStart('character',str_tmp.length+1);
   str_tmp = "";
   for(I=ln; I<arr.length; I++) {
       str_tmp += arr[=I];
   }
   rng.moveEnd('character',-str_tmp.length);
   rng.select();
   return;
}

window.onload = function() {document.getElementById("txt_main").value = "<script>\nalert(')\n<\/script>";}
</script>
<BODY>
<table width='600' class='list' border='1' bgcolor='#eeeeee' bordercolorlight='#000000' bordercolordark='#FFFFFF' cellpadding='0' cellspacing='0'>
  <tr bgcolor='#cccccc'>
   <td colspan='2' height='20' align='center'><b>Debug Textarea</b></td>
  </tr>
  <tr>
   <td colspan='2'>
       <table width='95%' border='0' align='center' >
     <tr>
       <td align='center'>
         <textarea id='txt_ln' name='content' rows='10' style='width:40px;overflow:hidden;height:200px;border-right:0px;text-align:right;line-height:14px' onselectstart='this.nextSibling.focus();return false' readonly></textarea><textarea id='txt_main' name='content' rows='10' cols='80' onkeydown='editTab()' onkeyup='show_ln()' onscroll='show_ln()' wrap='off' style='overflow:auto;height:200px;padding-left:5px;border-left:0px;line-height:14px'></textarea>
         <script>for(var I=1; I<=20; I++) document.getElementById('txt_ln').value += I + '\n';</script>
       </td>
     </tr>
         <tr>
           <td align='center'>
             <input type='button' value=' 运 行 ' onclick='runcode()' accesskey='r'>  
             <input type='button' value=' 保 存 ' onclick='savecode()' accesskey='s'>  
             <input type='button' value=' 跳 转 ' onclick="goto(prompt('Please input the line number', '1'))"  accesskey='g'>  
           </td>
         </tr>
       </table>
   </td>
  </tr>
</table>
</BODY>
</HTML>
-----------------------------------------------------------------------------------
TAB键在文本域中的体现
-----------------------------------------------------------------------------------
<script>
function editTab()
{
   var code, sel, tmp, r
   var tabs=""
   event.returnValue = false
   sel =event.srcElement.document.selection.createRange()
   r = event.srcElement.createTextRange()

   switch (event.keyCode)
   {
       case (8)    :
           if (!(sel.getClientRects().length > 1))
           {
               event.returnValue = true
               return
           }
           code = sel.text
           tmp = sel.duplicate()
           tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top)
           sel.setEndPoint("startToStart", tmp)
           sel.text = sel.text.replace(/^\t/gm, "")
           code = code.replace(/^\t/gm, "").replace(/\r\n/g, "\r")
           r.findText(code)
           r.select()
           break
       case (9)    :
           if (sel.getClientRects().length > 1)
           {
               code = sel.text
               tmp = sel.duplicate()
               tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top)
               sel.setEndPoint("startToStart", tmp)
               sel.text = "\t"+sel.text.replace(/\r\n/g, "\r\t")
               code = code.replace(/\r\n/g, "\r\t")
               r.findText(code)
               r.select()
           }
           else
           {
               sel.text = "\t"
               sel.select()
           }
           break
       case (13)    :
           tmp = sel.duplicate()
           tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top)
           tmp.setEndPoint("endToEnd", sel)

           for (var I=0; tmp.text.match(/^[\t]+/g) && I<tmp.text.match(/^[\t]+/g)[0].length; I++)    tabs += "\t"
           sel.text = "\r\n"+tabs
           sel.select()
           break
       default        :
           event.returnValue = true
           break
   }
}
</script>

<textarea cols=75 rows=20 onkeydown="editTab()">
<script>
alert("ok")
</script></textarea>

-----------------------------------------------------------------------------------
获取input的非value值,而是显示文本值
-----------------------------------------------------------------------------------
<select name="sss" onChange="alert(this.options[this.selectedIndex].text)">
<option value="1">asdf</option>
<option value="2">bbbb</option>
<option value="3">ccc</option>
</select>
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|金光论坛

GMT+8, 2024 年 11 月 19 日 17:25 , Processed in 0.146869 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表