<input
 onkeypress="return event.keyCode>=48&&event.keyCode<=57||event.keyCode==46"
 onpaste="return !clipboardData.getData('text').match(/\D/)"
 ondragenter="return false"
 style="ime-mode:Disabled"
>

解决方案 »

  1.   

    <input onkeyup="value=value.replace(/[^\d.]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d.]/g,''))" ID="Text2" NAME="Text2">
      

  2.   

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    </head><body>
    <form name="form1" method="post" action="">
      <input type="text" name="textfield" onkeyup="onlyNumber(this);" onChange="onlyNumber(this);">
    </form>
    <script language="javascript">
     function onlyNumber(e){
       if(isNaN(parseFloat(e.value))){
         return e.value="";
       }
       if(parseFloat(e.value)!=e.value){
         return e.value=parseFloat(e.value);
       }
     }
    </script>
    </body>
    </html>