<form name=form1><input type=text onpropertychange="if (this.value==this.value2) return; if (this.value.search(/^\d*(?:\.\d{0,2})?$/)==-1) this.value=(this.value2)?this.value2:'';else this.value2=this.value;"></form>应该可以了,你把onpropertychange=........... 贴上去用就可以,解释起来太麻烦……

解决方案 »

  1.   

    mjpclab(我是大猫猫啊 mjpclab.8u8.com) ---------
    我看了,不可以呀。
    还有能在输入的时候就执行吗,不要切换光标的时候这样。
      

  2.   

    function aa(){
    var a,b
    a=document.form1.text1.value
    b=a.lenght
    if (b==5){
       if (a.substring(0,1)%2==1){
          if(a.substring(0,1)%2==0){
             if(a.substring(1,2)%2==1{
                if(a.substring(1,2)%2==0){
                   if(a.substing(2,3)=="."){
                      if(a.substring(3,4)%2==0){
                        if(a.substring(3,4)%2==1){
                          if(a.substring(4,5)%2==0){
                             if(a.substring(4,5)==0){
                              }
                              else{
                               document.alert(输入有误)
                               document.form1.text1.focus()
                                  } 
                           else{
                              if(a.substring(4,5)==""){
                                }
                               else{
                               document.alert(输入有误)
                               document.form1.text1.focus()
                                   }
                                }
                              }
                          else{
                           document.alert(输入有误)
                           document.form1.text1.focus()
                            }
                     }
                  } 
               }
             }
          }
    }
      

  3.   

    上面有误
    <script>
    function aa(){
    var a,b,c,d
    a=document.form1.text1.value
    var b=a.lenght
    if (b<=5){
     for (c=0;c=b;c++){
         d=1+c
         if(a.substr(c,d)%2==0){
         if(a.substr(c,d)%2==1){
     }
     else{
     document.alert("输入有误")
     document.form1.text1.focus()
     document.form1.value=""
     }
     }
    if (c==2){
        if (a.substr(c,d)=="."){
    }
    else{
    document.alert("输入有误")
     document.form1.text1.focus()
     document.form1.value=""
     }
     }
     if (c==3){
        if(a.substr(c,d)==""){
       }
    else{
    if (a.substr(c,d)%2==1){
        if(a.substr(c,d)%2==0){
      }
     else{
     document.alert("输入有误")
     document.form1.text1.focus()
     document.form1.value=""
     }
     if (c==4){
      if(a.substr(c,d)==""){
       }
    else{
    if (a.substr(c,d)%2==1){
        if(a.substr(c,d)%2==0){
      }
     else{
     document.alert("输入有误")
     document.form1.text1.focus()
     document.form1.value=""
     }
     }
     }
     }
     else{
     document.alert("输入有误")
     document.form1.text1.focus()
     document.form1.value=""
     }
     }
    }
    abc=setTimeout("aa();10)
    aa();
    </script>
    <form name=form1 action="">
    <input type="text" name="text1">

    <input type="text" name="text1" onclick=aa()>
    </form>
      

  4.   

    onpropertychange的内容不是1行是3行啊,你把整个代码放一个新的页面试试
      

  5.   

    唉……
    <script language="JavaScript">
    function check()
    {
    var k = event.keyCode
    var v = t.value
    var hasdot = (v.indexOf(".")==-1)?false:true
    var l = v.length
    if (event.shiftKey) event.returnValue = false
    else if (l == 0)
    {
    if (k<48 && k!=8 && k!=36||k>57 && k<96 || k>105 && k!=109  &&  k!=189) event.returnValue = false
    }
    else if (l == 1)
    {
    if (v == "-")
    {
    if (k<48 && k!=8 && k!=36||k>57 && k<96 || k>105) event.returnValue = false
    }
    else if (v == "0")
    {
    if (k!= 8 && k!= 36 && k!=110  &&  k!=190) event.returnValue = false
    }
    else
    {
    if (k<48 && k!=8 && k!=36||k>57 && k<96 || k>105 && k!=110  &&  k!=190) event.returnValue = false
    }
    }
    else if (v=="-0")
    {
    if (k<=48 && k!=8 && k!=36||k>57 && k<=96 || k>105 && k!=110  &&  k!=190) event.returnValue = false
    }
    else 
    {
    if (k<48 && k!=8 && k!=36||k>57 && k<96 || k>105 && k!=110 && k!=190) event.returnValue = false
    if (hasdot && (k==110 || k==190)) event.returnValue = false
    }
    }
    </script>
    <input type="text" id="t" onKeyDown="check()">
      

  6.   

    小数点后数字限制:在if前加
    if (hasdot && v.indexOf(".")+3==l)
    {
      event.returnValue = false
      return
    }限制粘贴在input 加onpaste="return false"
      

  7.   

    大家我试了,好象还是不行,
    下面是我的代码:(可以限制输入数字之外的其他字符,但不能控制小数点后两位

    <input type="text" name="textfield2" 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">
    大家可以自己使用,在上面的代码中改改
      

  8.   

    偶给你写了一个,其它的验证,需要你自己加上,但是绝对能实现你要的功能.
    要是有问题,你在问我.绝对帮你解决.<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Description" CONTENT="">
    <script>
    function test(str){
        var pos;
        var fst
        var lst;
        if (str == "") return;
        pos = str.indexOf(".");
        if (pos != -1){
            fst = str.substring(0,pos);
            lst = str.substring(pos+1,pos.length);
            if (lst.length > 2){             
                 var sub = lst.substring(0,2);
                 textfield2.value=fst+"."+sub;
            }
        }    
    }
    </script>
    </HEAD><BODY>
    <input type="text" name="textfield2" onkeyup="test(this.value)"
                    onpaste="return !clipboardData.getData('text').match(/\D/)"
                    ondragenter="return false"
                    style="ime-mode:Disabled">
    </BODY>
    </HTML>