简体   繁体   中英

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:

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

I want to know if it is possible to format the text inside the alert() function.

In particular I want to know if (and how) is it possible to put some formatted HTML text as alert() input parameter.

Some one can help me?

No, alert() accepts one string argument and will display it as is.

If you need to display a formatted text in a modal, use a library (eg 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("first line \\n second line \\n third line");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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