<input onkeyup='value=value.replace(/[^0-9]/,"")'>

解决方案 »

  1.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <!-- saved from url=(0028)http://3http.com/js/1/01.htm -->
    <HTML><HEAD>
    <META http-equiv=Content-Type content="text/html; charset=unicode">
    <META content="MSHTML 6.00.2800.1106" name=GENERATOR></HEAD><IE:DOWNLOAD 
    id=oDownload style="BEHAVIOR: url(#default#download)" /><HEAD><LINK 
    href="只允许输入数字.files/03.css" type=text/css rel=stylesheet></HEAD>
    <BODY><TEXTAREA id=ok2 rows=7 cols=100></TEXTAREA> 
    <DIV align=center><INPUT onmousedown=runEx() title="???????<input" 
    onclick="ok2.select();document.execCommand('Copy')" type=image 
    src="只允许输入数字.files/02.gif">
    <DIV id=wri></DIV>
    <SCRIPT>
    function onDownloadDone(n){
    ok2.value=n
    setTimeout('asdfasf23(ok2.value)',500)
    }
    oDownload.startDownload(location.hash.substr(1)+".htm",onDownloadDone)function asdfasf23(n){
    var re;
    //re=/ (\d+)>/g;n=n.replace(re,"`vs2`#ff0000 $1>`1`1")
    re=/<script(\s*\S*\s*\S*)>/gi;n=n.replace(re,"`vS2`#0000ff><script$1>`1`1")
    re=/<\/script>/gi;n=n.replace(re,"`vS2`#0000ff></"+"script>`1`1")
    re=/<body/gi;n=n.replace(re,"`vS2`\"\"style=\"background-color:#99CCFF\"><body`1`1")
    re=/<\/body>/gi;n=n.replace(re,"`vS2`\"\"style=\"background-color:#99CCFF\"></body>`1`1")
    re=/(var|if|else|for)/g;n=n.replace(re,"`vS2`#0000ff>$1`1`1")
    re=/(function\s\S+\s*\(\S*\)|{|})/g;n=n.replace(re,"`vS2`#ff0000>$1`1`1")
    re=/(\(|\))/g;n=n.replace(re,"`vS2`#f00fff>$1`1`1")
    re=/\/\/(\S*)/g;n=n.replace(re,"`vS2`#00aa00>\/\/$1`1`1")re=/</g;n=n.replace(re,"&lt;")
    re=/\n/g;n=n.replace(re,"<br>")
    re=/`vS2`/g;n=n.replace(re,"<font color=")
    re=/`1`1/g;n=n.replace(re,"<\/font>")
    wri.innerHTML=n
    }
    function runEx(){
    var winEx=window.open("", "winEx","status=yes,menubar=yes,scrollbars=yes,resizable=yes");
    winEx.document.open("text/html","replace");winEx.document.write(ok2.value);winEx.document.close()}
    </SCRIPT>
    </DIV></BODY></HTML>
      

  2.   

    <input type=text size=8 onkeyup=math3(this) onBlur=math3(this)><script>
    function math3(n){
    n.value=n.value.replace(/\D/g,'')
    }
    </script>
      

  3.   

    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>只输入数字的几种方法</title>
    <style>
    td{font-size:12px}
    </style>
    </head><body><table border="1" width="90%" bordercolor="#000000" cellspacing="0" cellpadding="0" bordercolorlight="#000000" bordercolordark="#FFFFFF">
      <tr>
        <td width="100%">&lt;input onkeyup=&quot;this.value=this.value.replace(/\D/g,'')&quot; 
          onafterpaste=&quot;this.value=this.value.replace(/\D/g,'')&quot;&gt; 
         <br>
         try:<input onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"></td>
      </tr>
      <tr>
        <td width="100%">&lt;input name=txt1 onchange="if(/\D/.test(this.value)){alert('只能输入数字');this.value='';}"><br> 
        try:<input name=txt1 onchange="if(/\D/.test(this.value)){alert('只能输入数字');this.value='';}"></td> 
      </tr>
      <tr>
        <td width="100%">&lt;input onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')"><br>
        try:<input onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')"></td> 
      </tr>
      
    </table></body></html>