-3
我有这个字符串02/11/2015 \n € \n
,我显示到一个弹出窗口。在我这样做之前,我使用RegEx将\n
替换为<br/>
。但它不起作用。正则表达式替换(/ n/g,“<br />”)不起作用
下面是代码:
message= "02/11/2015 \n € \n";
message= message.replace(/\n/g, "<br />");
var popup = $('<div><span style="font-weight: bold; color: #1d5987;"> <p>'+ message+'</p> </span></div>');
$('document').append(popup);
popup.dialog({
autoOpen : true,
modal : true,
resizable: false,
width:'45%',
height: 'auto',
close: function(event, ui){
$(this).dialog('destroy');
}
});
在弹出02/11/2015 \n € \n
再次出现。
我使用chrome控制台来调试它,在消息字符串中执行替换函数后没有任何更改。
'message = message.replace(/ \ n/g,“
”);'它代替'\ n'请参阅http:///jsfiddle.net/a5xn49hv/ – Satpal
你有没有文字'\ n's?然后使用'/ \\ n/g'。或者如果你有他们的混合,'/ \\ n | \ n/g'。 –