简体   繁体   中英

Including line-break when displaying date within a div

I need to display the date to a DIV formatted with the day centered above the month (DD
MMMM). However, the page only displays the day. When I inspect element the line break and month are being sent properly.

JQuery

$(document).ready(function () {    

    var value = moment().subtract(2,'days');

$(".slider").each(function() {
    var dateFormatted = moment(value).format("DD" + "<br/>" + "MMMM");

    $(this).html(dateFormatted);
    value = value.add(1,'days');
});}

HTML

    <div class="carousel-items">
    <div class="slider"></div>
    <div class="slider"></div>
    <div class="slider"></div>
    <div class="slider"></div>
    <div class="slider"></div>
    <div class="slider"></div>
    <div class="slider"></div>
    <div class="slider"></div>
</div>

I could also use a suggestion for another technique to accomplish the same thing. But I do need an each loop in the JQuery because the dates will be generated continuously.

Thanks!

Answered

The height of the DIV appeared large enough to contain both lines, but after a few suggestions, I double checked the CSS and discovered the month was in fact returned to the page but just way below.

尝试转义<br>标签,例如。

moment(value).format('DD\\<\\\\b\\\\r\\>MMMM')

do you mean <br> you can add it class <br class="..."> though I always prefer using text-decoretion:underline; or border-bottom:1px solid black;

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