简体   繁体   中英

\n as well as <br> for new line in JavaScript alert not working

I am using a JavaScript alert (a little modified though). This alert has a title field and a content field. In my content field I want to display some text in new line, but neither \n nor <br> is working. See the image to check the output of the given code.

new Attention.Alert({
                title: 'School',
                content: 'Date - '+v_date+'\n School Name - '+ school_name + "\n School City - " + school_city + " "
            });

在此处输入图像描述

You just have to add CSS white-space: pre-line; for popup content.

Here is working Example.

 jQuery(document).ready(function($) { $('button').click(function(e){ e.preventDefault(); var v_date = '04/11/2019'; var school_name = 'School Name'; var school_city = 'School City'; new Attention.Alert({ title: 'This is a Title', content: 'Date - '+v_date+'\n School Name - '+school_name+'\n School City - '+school_city }); }); });
 *, *:after, *:before{ box-sizing: border-box; } body { font-family: 'Open Sans', serif; background-color: #d1d8de; padding: 20px; }.attention-component.inner-container p{ white-space: pre-line; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://janmarkuslanger.github.io/attention.js/dist/attention.js"></script> <link href="https://janmarkuslanger.github.io/attention.js/dist/attention.css" rel="stylesheet"> <button>Click</button>

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