这是我的文本框:<input type="text" name='account'id='account' value="$!amount" size='10'>
请问怎样限定文本框输入的只能是数字? javascript方法或者其他方法都可以,请教各位了

解决方案 »

  1.   

    if(isNaN(document.getElementByID('account').value))
    {
        //isNaN=is Not a Number...
    }
      

  2.   

     <input type="text" name='account'id='account' value="$!amount" size='10' onkeyup="value=value.replace(/[^\d]/g,'')" >
      

  3.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
        <head>
            <script type="text/javascript">
        function Money(){
            var price = document.all.Price.value;
            //判断
            if(isNum(price)){
            //是就弹出
            alert("price中包含:"+price);
            }
            return;
        }
        //是否为数字或小数
        function isNum(s) { 
        var patrn=/^(-?\d+)(\.\d*)?$/; 
        if (!patrn.exec(s)) return false ;
            return true 
        }
        </script>
        </head>
        <body>
            <input type="text"  name="Price"  >
            <input type="button"  value="test" onclick="Money()" />
        </body>
    </html>
      

  4.   

    <input type="text" onkeyup="check(value,this)"/><script>
    function check(value,text) {
     if(isNaN(value)){
      alert("input not a number");
      text.select(0);
     }
    }
    </script>
      

  5.   

     var patrn=/^(-?\d+)(\.\d*)?$/; 
        if (!patrn.exec(s)) return false ;
            return true 
        }
    怎么又false 又true?
      

  6.   

    <input type="text" onkeyup="check()" id="test"/> <script> 
    function check() { 
    var value=document.getElementById("test").value;
    if(isNaN(value)){ 
      alert("只能输入数字"); 
     document.getElementById("test").value=""


    </script> 
      

  7.   

    <input type="text" onkeyup="check()" id="test"/> <script> 
    function check() { 
    var value=document.getElementById("test").value;
    if(isNaN(value)){ 
      alert("只能输入数字"); 
     document.getElementById("test").value=""


    </script>