Javascript Alert()方法中的HTML标签 [英] HTML Tags in Javascript Alert() method

查看:1407
本文介绍了Javascript Alert()方法中的HTML标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能为Javasript Alert()方法添加html标记,例如

 < b> ; 
< ul>
< li>

等。

感谢您的帮助

解决方案

您可以使用所有Unicode字符和转义字符 \\\
\t 。例如:

document.getElementById(test)。onclick = function (){alert('This is a alert with basic formatting \\\
\\\
'+\t•list item 1 \\\
+'\t•list item 2\\\
'+'\ t•列表项目3 \\\
\\\
'+'▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬▬\\\
\\\
'+'简单的桌子\ n'\
'+'Char\t | Result\\\
'+'\\\\
\t | line break\\\
'+'\\t\t | tab space'); }

<!DOCTYPE html>< title> Alert < / button>< / code>< / pre>< / div>< / div>< p>

Re在Firefox中出现问题:





几乎所有的浏览器都有相同的外观。


I wanted to know if it's possible to add html tags to Javasript Alert() method, such as

<b>
<ul>
<li>

etc.

Thanks for your help

解决方案

You can use all Unicode characters and the escape characters \n and \t. An example:

document.getElementById("test").onclick = function() {
  alert(
    'This is an alert with basic formatting\n\n' 
    + "\t• list item 1\n" 
    + '\t• list item 2\n' 
    + '\t• list item 3\n\n' 
    + '▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬▬\n\n' 
    + 'Simple table\n\n' 
    + 'Char\t| Result\n' 
    + '\\n\t| line break\n' 
    + '\\t\t| tab space'
  );
}

<!DOCTYPE html>
<title>Alert formatting</title>
<meta charset=utf-8>
<button id=test>Click</button>

Result in Firefox:

You get the same look in almost all browsers.

这篇关于Javascript Alert()方法中的HTML标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆