2016-04-22 12 views
0

ブートストラップモーダル(shown.bs.modal)で2つのイベントを使いたいと思います。 クリックだけで作業しています。 $('id').click('shown.bs.modal, function(e) { $('#regModal').modal('show');}Boostrapモーダル - ボタンにクリックイベントとキーイベントがあります

しかし、2つのイベントでは機能しません。

$('id').bind("keypress shown.bs.modal", function (e) {... }

はどのようにして、ボタンに2つのイベントが使用できますか?

答えて

0

リスナーをモーダル自体に追加すると思います。

$('#myModal').on('shown.bs.modal', function(e) { 
    // hold a reference to the triggering button in case you need it 
    var $button = $(e.relatedTarget); 
    // handler code here, executed after the modal is shown 
}); 

は、モーダルをトリガ指定した要素が別のイベントに応答する場合

$('#myButton').on('click', function() { 
    $('#myModal').modal(); 
}); 
0

を使用するには、別途、これらのイベントを定義する必要があります。

あなたの例:

$('id').click('shown.bs.modal, function(e) { $('#regModal').modal('show');} 

は次のようになります。

var showModal = function(){ $('#regModal').modal('show'); }; 
$('id').on('shown.bs.modal', showModal()); 
$('id').on('click', showModal()); 
関連する問題