简体   繁体   English

我可以将格式化的HTML代码作为Javascript alert()输入参数吗?

[英]Can I put formatted HTML code as Javascript alert() input parameter?

I have this simpe Javascript script that show a popup box when a link is clicked: 我有这个simpe Javascript脚本,在单击链接时会显示一个弹出框:

    <script>
        function myExample() {
            alert("BaZing!  It works!");
        }
    </script>

I want to know if it is possible to format the text inside the alert() function. 我想知道是否可以格式化alert()函数内的文本。

In particular I want to know if (and how) is it possible to put some formatted HTML text as alert() input parameter. 特别是我想知道是否可以(以及如何)将一些格式化的HTML文本作为alert()输入参数。

Some one can help me? 有人能帮帮我吗?

No, alert() accepts one string argument and will display it as is. 不, alert() 接受一个字符串参数,并按原样显示。

If you need to display a formatted text in a modal, use a library (eg Alertify.js ). 如果需要在模态中显示格式化文本,请使用库(例如Alertify.js )。

alert() can't format a HTML format string, but if you just want separate a string to several lines, you can put '\\n' in your string,like alert()无法格式化HTML格式字符串,但如果您只想将字符串分隔为多行,则可以在字符串中添加'\\ n',如

alert("first line \\n second line \\n third line"); 警报(“第一行\\ n第二行\\ n第三行”);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM