本来js写个正则来限制数字输入还ok的……
(?:\d{1,3}\.){3}(?:\d{1,3})代码就不写给你看了,认真的去学js!

解决方案 »

  1.   

    <HTML>
    <script>
    function check(n,obj){
    if(n!=""){
    if(isNaN(n)){
    obj.value = n.substring(0,n.length-1);
    }else{
    var val = new Number(n);
    if(val>255){
    obj.value = n.substring(0,n.length-1);
    }
    }
    }
    }
    </script>
    <HEAD>
    <BODY>
    <input type="text" onKeyUp="check(this.value,this)">
    </BODY>
    </HTML>
      

  2.   


    <SCRIPT LANGUAGE="JavaScript">
    function IPcheck(ip) 

    var exp=/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/; 
    alert(exp.test(ip)); 

    </SCRIPT>
    <INPUT TYPE="text" NAME="" onblur="IPcheck(this.value)">onblur事件触发
      

  3.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        </head>
        <SCRIPT LANGUAGE="JavaScript">
            <!--
            function $(id){
                return document.getElementById(id);
            }
            
            function test(obj){
                var s = obj.value;
                if (!s || s.length == 0) {
                    return;
                }
                
                r = /^((1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d?|0)\.){3}(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d?|0)$/;
                if (!r.test(s)) {
                    alert("input error!");
                    setTimeout('$("' + obj.id + '").select();', 1);
                }
            }
            
            //-->
        </SCRIPT>
        <body>
            <table width="400">
                <tr>
                    <td>
                        <table width="87%" height="73" border="0" align="center" cellpadding="0" cellspacing="1">
                            <tr>
                                <td width="44%" height="24" align="right">
                                    IP地址:
                                </td>
                                <td width="56%" align="left">
                                    <input name="ip" type="text" id="ip" value="" onchange="test(this);"/>
                                </td>
                            </tr>
                            <tr>
                                <td width="44%" height="24" align="right">
                                    子网掩码:
                                </td>
                                <td width="56%" align="left">
                                    <input name="netmask" type="text" id="netmask" value="" onchange="test(this);"/>
                                </td>
                            </tr>
                            <tr>
                                <td width="44%" height="24" align="right">
                                    默认网关:
                                </td>
                                <td width="56%" align="left">
                                    <input name="gateway" type="text" id="gateway" value="" onchange="test(this);"/>
                                </td>
                            </tr>
                            <tr>
                                <td height="24" align="right">
                                    服务器别名:
                                </td>
                                <td align="left">
                                    <input name="servername" type="text" id="servername" value="" />
                                </td>
                            </tr>
                        </table>
                        <table width="87%" height="24" border="0" align="center" cellpadding="0" cellspacing="1">
                            <tr>
                                <td height="25" align="center">
                                    <input name="tijiao" type="submit" class="btn" border="0" value="确 定">&nbsp; <input type="checkbox" value="1" id="chkLock" onclick="lock(this)" name="chkLock" />
                                    <label for="chkLock">
                                        启用DHCP
                                    </label>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </body>
    </html>