如何为bootstrap模式添加换行符

时间:2014-08-01 02:58:12

标签: html modal-dialog line-breaks bootstrap-modal

我一直在尝试并且没有为DRY bootstrap模式添加换行符。

这是我的超链接模板代码,它将消息发送到模态显示代码:

<a href="{% url achievement_details_delete achievement_detail.id %}" delete-confirm="Are you sure you want to DELETE the selected record? <br /><br />This action will permanently remove the record.">Delete</a>

这是我的jquery bootstrap模态代码:

$(document).ready(function() {

    //START: Delete code.
    $('a[delete-confirm]').click(function(ev) {

        var href = $(this).attr('href');

        if (!$('#deleteConfirmModal').length) {

            $('body').append('<div id="deleteConfirmModal" class="modal modal-confirm-max-width" role="dialog" aria-labelledby="deleteConfirmLabel" aria-hidden="true"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">X</button><h4 class="modal-title" id="deleteConfirmLabel">{% trans "Delete" %} - {{ resume_details_trans }}</h4></div><div class="modal-body"></div><div class="modal-footer"><button class="btn" data-dismiss="modal" aria-hidden="true">{% trans "Cancel" %}</button>&nbsp;&nbsp;<a class="btn-u btn-u-red" id="deleteConfirmOK" onclick="showProgressAnimation();">{% trans "Delete" %}</a></div></div>');

        }

        $('#deleteConfirmModal').find('.modal-body').text($(this).attr('delete-confirm'));

        $('#deleteConfirmOK').attr('href', href);

        $('#deleteConfirmModal').modal({show:true});

        return false;

    });
    //FINISH: Delete code.
});

1 个答案:

答案 0 :(得分:6)

将此添加到按钮以删除记录:

<a href="url"
   delete-confirm="Your Message Here!!<br /><br /><span class='confirm_delete_warning_red_bold'>You can even add in css to highlight specific text - Are you sure?</span>"
>
    Delete
</a>

在你的jquery代码中将.text更改为.html。文本将呈现文本,.html将充当html并在span标记中显示换行符和css。

 $('#deleteConfirmModal').find('.modal-body').html($(this).attr('delete-confirm'));

这适用于您的代码。只是看你使用&#39;和&#34; (单一和双重谈话标记)。不要混淆它们。