| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 430 人关注过本帖
标题:给个解释啊。为什么
只看楼主 加入收藏
mks0101
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2011-4-13
结帖率:80%
收藏
已结贴  问题点数:10 回复次数:1 
给个解释啊。为什么
missing ; before statement
[在此错误处中断] msg = "输入的Email为: "" + str + ""\r\n" ;       (19行)

<html>
<head>
<mete http-equiv="content-type" content="text/html;charset=GB2312" />
<title>9-2 判断用户输入是否符合"Email"地址格式 </title>
<!--样式表 -->
<style>
*{font-size:12px;font-family:宋体,Arial;font-weight:normal;color:#333; } /*规定了所有的字体样式*/
</style>
<script>
    function check(){
        var str, result1, result2, timecost1, timecost2, timer, msg;
        str = document.getElementById("txtEmail").value;
        timecost1 = (new Date()).getTime();
        for(var i=0;i<1000;i++)validateEmailByReg(str);
        timecost1 = (new Date()).getTime() - timecost1;
        timecost2 = (new Date()).getTime();
        for(var i=0;i<1000;i++)validateEmail(str);
        timecost2 = (new Date()).getTime() - timecost2;
        msg = "输入的Email为: "" + str + ""\r\n" ;
        msg += "用正则测试的结果为: \t" + (validateEmailByReg(str)?"通过":"不通过") + "运算1000遍耗时" + timecost1 + "毫秒。 \r\n";
        msg += "不用正则测试的结果为: \t" + (validateEmail(str)?"通过":"不通过") + "运算1000遍耗时" + timecost2 + "毫秒。 \r\n";
        alert(msg);
    }
    function validateEmailByReg(str){
        return(/^\w+([-+.]\w+)*@\w([-.]\w+)*\.\w+([-.]\w+)*$/.test(str));
    }
    function validateEmail(str){
        var flg01, flg02, previousCharType;
        flg01 = false;
        flg02 = false;
        for(var i=1; i<str.length; i++){
            switch(charType(str.charAt(i))){
                case "ascii":
                    if(previousCharType!="ascii")previousCharType = "ascii";
                break;
                case "-":
                    if(previousCharType!="ascii")return(false);
                    previousCharType = "-";
                break;
                case ".":
                    if(previousCharType!="ascii")return(false);
                    if(flg01)flg02=true;
                    previousCharType = ".";
                break;
                case "+":
                    if(previousCharType!="ascii" || flg01)return(false);
                    previousCharType = "+";
                break;
                case "@":
                    if(previousCharType!="ascii" || flg01)return(false);
                    previousCharType = "@";
                break;
                default:
                    return(false);
                break;
            }
        }
        if(!flg01 || !flg02)return(false);
        return(true);
    }
   
    function charType(val){
        var asciiChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        if(asciiChars.indexOf(val)!=-1){
            return("ascii");
        }else{
            return(val);
        }
        </script>
      </head>
      <body style="overflow:auto;">
          E-Mail:
          <input id="txtEmail"><br/>
          <input type="button" value="测试" onclick= "check()">
      </body>
    </html>
搜索更多相关主题的帖子: function content Email style 用户 
2011-04-20 19:40
foktime
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:奥斯维辛
等 级:贵宾
威 望:35
帖 子:795
专家分:2742
注 册:2009-9-4
收藏
得分:10 
function charType(val) {
        var asciiChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        if (asciiChars.indexOf(val) != -1) {
            return ("ascii");
        } else {
            return (val);
        }
    }
msg = "输入的Email为: " + str + "\r\n" ;

全是粗心马虎导致

2011-04-21 16:23
快速回复:给个解释啊。为什么
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.046711 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved