我需要一个函数来过滤Javascript中的消息
变量msgText是您想要填充的消息的位置。
她是这样来的:<!-- react-text: 1052 -->Message Here<!-- /react-text -->
这里是我调用函数的地方:
msgText = $(msgTextSelect).html();
msgText = analyseElem(msgText);
debug(msgText);所以,我希望在过滤器之后,它返回如下:消息这里
我组装的过滤器坏了,所以我想知道我做错了什么
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;
}发布于 2016-08-03 18:18:12
尝试这个函数--它移除HTML注释,这就是您的react标记:)
function filter(text){
return text.replace(/<!--[\s\S]*?-->/g, "")
}
$("#output").html(filter("<!-- react-text: 1052 -->Message Here<!-- /react-text -->"))<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="output"></div>
工作jsFiddle:https://jsfiddle.net/r7upndeh/
https://stackoverflow.com/questions/38750847
复制相似问题