HTML Tags in Javascript Alert() method

前端 未结 6 2160
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-01 06:17

I wanted to know if it\'s possible to add HTML tags to JavaScript alert() method, such as:


et

6条回答
  •  醉话见心
    2020-12-01 06:39

    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'
      );
    }
    
    Alert formatting
    
    

    Result in Firefox:

    screenshot Firefox

    You get the same look in almost all browsers.

提交回复
热议问题