链接:<input type="text" value="" name="url"/>
想写一个js函数,验证我在输入框里面的文本必须以.jsp、.php、.html、.asp(其中一个)结尾

解决方案 »

  1.   

    那你就去使用substring去截取出你的后缀名在去判断咯。
      

  2.   

    L@_@K
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
      <title> new document </title>
      <meta name="generator" content="editplus" />
      <meta name="author" content="" />
      <meta name="keywords" content="" />
      <meta name="description" content="" />
     </head> <body>
    <input type="text" value="" name="url" /> 
      <script type="text/javascript">
      <!--
    document.getElementById("url").onchange = function() {
    var sUrl = this.value;
    var reg = /\.(jsp|php|html|asp)$/i;
    if (reg.test(sUrl))
    {
    return true;
    }
    else
    {
    alert("请输入以 .jsp|.php|.html|.asp 结尾的地址!");
    return false;
    }
    };
      //-->
      </script>
     </body>
    </html>
      

  3.   

    Web 开发常用手册JScript语言参考.rar
    http://download.csdn.net/source/308916DHTML参考手册.rar
    http://download.csdn.net/source/308913样式表中文手册.chm
    http://download.csdn.net/source/304124
      

  4.   


    function isFile(input, filter){
    return new RegExp("^.+\.(?=EXT)(EXT)$".replace(/EXT/g, filter.split(/\s*、\s*/).join("|")), "gi").test(input);
    }测试:
    isFile(“nihao.jsp”,“.jsp、.php、.html、.asp”);