2016-12-17 4 views
1

を設定は、私は私のモーダルを持っているモーダルタイトル

$('.call-modal').on('click', function(e){ 
    e.preventDefault(); 
    $('#defaultModal') 
    .find('.modal-header > h3').text("Teste").end()    
    .find('.modal-body').load($(this).attr('href')).end()    
    .modal('show'); 
}); 

私はコンテンツを読み込むことができますが、データタイトルを使用してタイトルを設定したいと思います。

なぜ機能しないのでしょうか?

はありがとう

+1

[問題はありません](http://www.bootply.com/aFodNF1hWI) – Jhecht

答えて

3
あなたはこのように行うことができます

$('#defaultModal').on('show.bs.modal', function (event) { 
    var button = $(event.relatedTarget); // Button that triggered the modal 
    var modal  = $(this); 
    var title = button.data('title'); alert(title); 
    modal.find('.modal-title').text(title) 
}); 

とあなたのボタン:

<button type="button" class="btn btn-success" data-toggle="modal" data-target="#defaultModal" data-title="New Data" ><i class="glyphicon glyphicon-plus"></i></button> 

フィドル:

http://jsfiddle.net/bhumi/hw154nda/1/

0

モーダルが表示されたらタイトルを設定できます。

$('#defaultModal').on('show.bs.modal', function (event) { 
    $(this).find('h3#modal-title').text("You new title"); 
}); 
関連する問題