Boostrap模式 - 一个按钮有cli​​ck和按键事件

时间:2016-04-22 18:58:29

标签: javascript jquery twitter-bootstrap

我想在bootstrap模式中使用两个事件(shown.bs.modal)。 它只适用于点击。  $('id').click('shown.bs.modal, function(e) { $('#regModal').modal('show');}

但它在两个事件中不起作用。

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

如何在按钮中使用两个事件?

2 个答案:

答案 0 :(得分: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();
});

答案 1 :(得分: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());
相关问题