简体   繁体   English

在引导程序中对同一元素使用两个数据切换

[英]Using two data-toggle for same element in bootstrap

I was messing around with Bootstrap and created a page which has a simple navigation menu. 我当时正忙着使用Bootstrap,创建了一个带有简单导航菜单的页面。 I wanted to add modal for one of the links, which already has a tooltip . 我想为其中一个链接添加模态,该链接已经有一个tooltip

And I did add the modal to li like this, 我确实将模式添加到li这样,

data-toggle="modal" data-target="#SettingsModal" data-toggle="tooltip"

Surprisingly, its working. 令人惊讶的是,它的工作原理。 It doesn't make much sense. 这没有多大意义。 Because at least one data-toggle has to be neglected. 因为必须忽略至少一个data-toggle

I know that it is better to wrap it inside an element which has tooltip . 我知道最好将其包装在具有tooltip的元素中。 My question is, how is this working? 我的问题是,这如何运作?

It's working because the Bootstrap data attributes use separate jQuery selectors to "activate" the various components. 之所以起作用,是因为Bootstrap 数据属性使用单独的jQuery选择器来“激活”各种组件。

Since $('[data-toggle="modal"]') and $('[data-toggle="tooltip"]') are both referenced in the Bootstrap JS code, both modal and tooltip components are working. 由于在Bootstrap JS代码中都引用了$('[data-toggle="modal"]')$('[data-toggle="tooltip"]') ,所以模态和工具提示组件都可以使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM