[英]javascript is not decoding html values
I am trying to achieve at below 我正在努力实现以下目标
var a = "how are you. <br> fine";
var b = "how are you, <br> fine";
alert(a);
alert(b);
Output should be 输出应为
How are you
fine
But It gives me 但这给了我
how are you. <br> fine
how are you, <br> fine
> < and   are in my string &gt&lt和&nbsp在我的字符串中
How can I decode this html in alert message of javascript 如何在javascript的警报消息中解码此html
Ty to use \\n
in place of <br>
like, 请使用\\n
代替<br>
,
var b = "how are you, \n fine";
alert(b);
To show HTML content
you can try jquery-alert 要显示HTML content
您可以尝试jquery-alert
Try this... 尝试这个...
var text = '<p>name</p><p><span style="font-size:xx-small;">ajde</span></p><p><em>da</em></p>';
var decoded = $('<div/>').html(text).text();
alert(decoded);
Edit: As Rohan Kumar has suggested above, I don't think it is possible to render HTML inside an alert box (which is what you are implying in your question). 编辑:正如Rohan Kumar上面建议的那样,我认为不可能在警报框中呈现HTML(这是您在问题中所隐含的含义)。 but rather you would need to do something like below, ie use replace or even better look into using a modal dialogue 但是相反,您将需要执行以下操作,即使用替换或使用 模态对话框 更好地了解
var text = 'how are you, <br> fine';
var text = text.replace('<br>','\n');
var decoded = $('<div/>').html(text).text();
alert(decoded); 警报(解码);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.