【发布时间】:2016-12-09 14:28:48
【问题描述】:
我需要一个函数来过滤 Javascript 中的消息
变量 msgText 是您要过滤的消息的位置
她是这样来的:<!-- react-text: 1052 -->Message Here<!-- /react-text -->
这里是我调用函数的地方:
msgText = $(msgTextSelect).html();
msgText = analyseElem(msgText);
debug(msgText);
所以,我想在过滤器之后,返回如下:Message Here
我组装的过滤器不起作用,所以我想知道我做错了什么
function analyseElem(text) {
var textMsg = msgText;
var filtro1 = "";
var filtro2 = "";
var filtro3 = "";
var filtro4 = "";
if(textMsg[0] == '<!--') {
var filtro1 = textMsg.replace(/<!-- react-text: /g,"");
var filtro2 = filtro1.replace(/<!-- \/react-text -->/g,"");
var filtro3 = filtro2.replace(/-->/g,"");
filtro3[0] = "" //to delete the random number
var filtro4 = filtro3.trim();
}
return filtro4;
}
【问题讨论】:
-
你已经问过这个问题了。 jQuery中的答案基本相同:
msgText = $(msgTextSelect).text(); -
对不起,我太笨了,我现在明白了,非常非常非常感谢
标签: javascript function filter tampermonkey