如何动态更改bootstrap模态体

VTo*_*rov 7 javascript jquery twitter-bootstrap

所以我将Bootstrap模态定义为:

   <div class="modal fade" id="myModal" role="dialog">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title">Error</h4>
                </div>
                <div class="modal-body">
                    <p> </p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>
Run Code Online (Sandbox Code Playgroud)

我想用jscript编辑空体.我是Javascript的初学者,所以我会感谢最简单的答案.

Ram*_*man 11

请看看这个小提琴.

这是代码:

$(function(){
  $('.custom-modal').click(function(e){
    e.preventDefault();
    var mymodal = $('#myModal');
    mymodal.find('.modal-body').text('hello');
    mymodal.modal('show');

  });
})
Run Code Online (Sandbox Code Playgroud)


Aja*_*ana 8

试试这个:

$('.modalShow').click(function(event){
    event.preventDefault();
    var e = $(this);
    var title = e.data('title');
    var body = e.data('value');
    $("#myModal").modal("show");
    $('#modal-title').html(title);
    $('#modal-body').html(body);
});
Run Code Online (Sandbox Code Playgroud)