我不明白为什么这不起作用,但如果你注释掉 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/