I have this string 02/11/2015 \n € \n
that I show into a popup. Before I do this I use a RegEx to replace \n
with <br/>
. But it doesn't work.
我有这个字符串02/11/2015 \ n€我显示为一个弹出\ n。在此之前,我使用RegEx替换\n与
。但它不工作。
Here is the code:
这是代码:
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');
}
});
In the pop-up 02/11/2015 \n € \n
appears again.
在弹出的02/11/2015 \n \n再次出现。
I use the chrome console to debug it, after replace function is executed in the message string there are no changes.
我使用chrome控制台调试它,替换函数在消息字符串中执行后没有变化。
1 个解决方案
#1
2
It works: Fiddle
工作原理:小提琴
You may have error in
你可能有错误。
$('document').append(popup);
The selector 'document'
is nothing. Use $(document)
without the quotes, or rather $('body')
or append directly to some element by ID
选择器“文档”什么都不是。使用$(document),不使用引号,或者$('body'),或者通过ID直接追加到某个元素。
#1
2
It works: Fiddle
工作原理:小提琴
You may have error in
你可能有错误。
$('document').append(popup);
The selector 'document'
is nothing. Use $(document)
without the quotes, or rather $('body')
or append directly to some element by ID
选择器“文档”什么都不是。使用$(document),不使用引号,或者$('body'),或者通过ID直接追加到某个元素。