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

验证提交的是否为域名
请教下js该怎么验证

------解决方案--------------------
HTML code

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="gb2312" />
        <title></title>
        <style>
        
        </style>
    </head>
    <body>
        <input id="a" />
        <button id="btn">测试</button>
        <script>
            function $(o){return document.getElementById(o);}
            
            var re = /^http:\/\/.+$/i;
            $('btn').onclick = function(){
                var t = $('a').value;
                alert(re.test(t))
            }
        </script>        
    </body>
</html>