-2

我不明白为什么这不起作用,但如果你注释掉 countGrin 函数,它工作得很好:

var DetectEmoticons = {
    countHappy: function(data) {
        var pattern = new RegExp("[:=]-?[)|\\]]|[(|\\[]-?[:=]", "g");
        var count = (data.match(pattern) || []).length;
        return count;
    }
    countGrin: function(data) {
        var pattern = new RegExp("[:=]-?[D]", "g");
        var count = (data.match(pattern) || []).length;
        return count;
    }
}
alert(DetectEmoticons.countHappy("=) :) :] :[ ]="));
alert(DetectEmoticons.countGrin(":D =D"));

这是jsfiddle:http: //jsfiddle.net/9BTAb/

4

1 回答 1

4

也许你缺少,第一个函数之后的SEE FIDDLE

var DetectEmoticons = {
    countHappy: function(data) {
        var pattern = new RegExp("[:=]-?[)|\\]]|[(|\\[]-?[:=]", "g");
        var count = (data.match(pattern) || []).length;
        return count;
    }, //put a comma here
    countGrin: function(data) {
        var pattern = new RegExp("[:=]-?[D]", "g");
        var count = (data.match(pattern) || []).length;
        return count;
    }
}
于 2013-06-06T06:02:06.707 回答