首页 > 请问bootstrap中on("shown.bs.modal")这样的事件 是怎么来的。貌似资料很少

请问bootstrap中on("shown.bs.modal")这样的事件 是怎么来的。貌似资料很少

dialog.on("shown.bs.modal", function() {
  dialog.find(".btn-primary:first").focus();
});



dialog.on("escape.close.bb", function(e) {
  if (callbacks.onEscape) {
    processCallback(e, dialog, callbacks.onEscape);
  }
});

1.bootstrap是基于jquery的,上面的on自然是jQuery中的事件监听方法;
2.jQuery中的事件机制是基于缓存做的,使得我们可以添加自定义事件(类似于观察者模式);
3.bootstrap中事件简单理解下:

html
-----


<div id="test">This is test div!</div>



js
-----
var relatedTarget = { relatedTarget: 111};
var e = $.Event('show.bs.test', relatedTarget)
$("#test").on('show.bs.test', function(e){
    console.log(e.relatedTarget);
});
$("#test").trigger(e);

console
----
111

这里的$.event是对事件的增强,bootstrap里面这样的代码很多,具体的可以查阅下相关资料;

【热门文章】
【热门文章】