3

Quick Question

I notice this in bootstrap that it was manage to use the right function by using the data attribute. Like in dropdowns, you can use data-toggle to initiate it. I would like to know how this works. This might save me time to declare each of them in .ready or .load

Thanks.

4

1 回答 1

4

它的工作方式与任何其他选择器(来自引导模式的代码)完全相同:

$('body').on('click.modal.data-api', '[data-toggle="modal"]', function ( e ) {
    // show modal
});

此绑定意味着:对于body该 fit选择器下的所有元素,通过指定的回调函数[data-toggle="modal"]处理事件click

于 2012-06-20T04:47:17.850 回答