简体   繁体   English

在 div 中显示日期时包括换行符

[英]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我需要将日期显示为以月为中心的日期格式的 DIV (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 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.但我确实需要在 JQuery 中使用 each 循环,因为日期将连续生成。

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. DIV的高度看起来足够大到可以包含两行,但是在提出了一些建议之后,我仔细检查了CSS,发现实际上该月已返回页面,但仅在下面。

尝试转义<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; 您是说<br>还是可以将其添加为类<br class="...">尽管我总是更喜欢使用text-decoretion:underline <br class="..."> or border-bottom:1px solid black; 或下边框:1px纯黑色;

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

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