日期:2014-05-16  浏览次数:20515 次

你这个这个JavaScript的属性么?
JScript code


<script type="text/javascript" src="../JS/jquery-min-lastest.js"></script>
    <script type="text/javascript" src="../JS/jquery.validate.min.js"></script>
    <script type="text/javascript">
        $().ready(function() {
            $("#form1").validate({
            rules: {
                    txtGRMS:   { required: true, minlength: 5 }
                },
                messages: {
                    txtGRMS:   { required: "不能为空!", minlength: jQuery.format("最少{0}个字符") }
                }
            });
        });
    </script>
</head>


我想问下,我要设置什么属性让它只能输入int型,或者只能输入float型,等等各方面的属性!
谢谢各位!



------解决方案--------------------
有的,按jquery的习惯应该是$("#form1").submit
------解决方案--------------------
HTML code
<html>
    <head>
        <script type="text/javascript">
            function inputInt(el){
                var format = /^[1-9]\d*$/;
                var str = "";
                var value = el.value.replace(/[^\x00-\xff]/g,"**");
                var len = value.length;
                if(value.length > 0){
                    for(var i=0;i<len;i++){
                        if(format.test(el.value.substring(0,i+1))){
                            str = el.value.substring(0,i+1);
                        }else{
                            el.value = el.value.substring(0,i);;
                            break;
                        }
                    }
                    
                }
            }
        </script>
    </head>
    <body>
        <input type="text" onpropertychange="inputInt(this)" />
    </body>
</html>