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

解决方案 »

  1.   

    <script  language="javascript">
    <!--
    if (document.layers)
    document.captureEvents(event.KeyPress);function blockA(e) {
    if (document.layers)
            var keyChar =e.which;
    if (document.all)
            var keyChar =event.keyCode;
    if (keyChar>57 || keyChar<48)
    {
    alert('请输入数字!');
    return false;
    }}document.form1.text5.onkeypress = blockA;   //需要更改的地方
    document.form1.text6.onkeypress = blockA;
    document.form1.text7.onkeypress = blockA;
    //-->
    </script>
      

  2.   

    <input onpropertychange="if(/\D/g.test(value))value=value.replace(/\D/g,'')">
      

  3.   

    在onkeypress事件中加入fucCheckNUM(NUM)//函数名:fucCheckNUM
    //功能介绍:检查是否为数字
    //参数说明:要检查的数字
    //返回值:1为是数字,0为不是数字
    function fucCheckNUM(NUM)
    {
     var i,j,strTemp;
     strTemp="0123456789";
     if ( NUM.length== 0)
      return 0
     for (i=0;i<NUM.length;i++)
     {
      j=strTemp.indexOf(NUM.charAt(i)); 
      if (j==-1)
      {
      //说明有字符不是数字
       return 0;
      }
     }
     //说明是数字
     return 1;
    }