Tips:replace()

来源:互联网 发布:java哈希表 编辑:程序博客网 时间:2024/06/05 19:50
         function htmlEscape(text){            return text.replace(/[<>"&]/g, function(match, pos, originalText){                switch(match){                    case "<":                        return "<";                    case ">":                        return ">";                    case "&":                        return "&";                    case "\"":                        return """;                }                         });        }                alert(htmlEscape("<p class=\"greeting\">Hello world!</p>")); //<p class="greeting">Hello world!</p>

0 0
原创粉丝点击