jQuery bootstrap 框架的“data-toggle”属性从何而来?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10481684/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where does "data-toggle" attribute of bootstrap framework come from?
提问by James
I am trying to use some of the jQuery plugins for the Bootstrap frameworkand they use an attribute named "data-toggle". I am getting the warning "attribute data toggle is not a valid atribute of a".
我正在尝试将一些 jQuery 插件用于Bootstrap 框架,它们使用名为“data-toggle”的属性。我收到警告“属性数据切换不是 a 的有效属性”。
Where does data-toggle come form?
数据切换从何而来?
回答by Richard Neil Ilagan
In HTML5, any attribute that starts with data-
is a valid customattribute. Basically, it's a way to attach custom data to elements that aren't explicitly defined in the HTML specification.
在 HTML5 中,任何以 开头的属性data-
都是有效的自定义属性。基本上,这是一种将自定义数据附加到 HTML 规范中未明确定义的元素的方法。
In earlier versions of HTML, this does not validate, however. Don't worry about that too much though. Browsers generally just ignore attributes they don't know about. This doesn't stop libraries like jQuery
from reading them.
然而,在早期版本的 HTML 中,这不会验证。不过不要太担心。浏览器通常只是忽略他们不知道的属性。这并不会阻止图书馆jQuery
阅读它们。
回答by cucu8
If you look in the JavaScript Collapse plugindocumentation of Bootstrap you will find a reasonably clear example of the workings of the collapse API and the relationship and uses of the pair data-toggle
(which triggers the functionality) and data-target
(which sets the behavior), plus other interesting tidbits.
如果您查看Bootstrap的JavaScript Collapse 插件文档,您会发现一个相当清晰的示例,说明了折叠 API 的工作原理以及对data-toggle
(触发功能)和data-target
(设置行为)的关系和使用,以及其他有趣的花絮。
回答by Daniel A. White
It is a Bootstrap defined HTML5 data attribute.
它是 Bootstrap 定义的 HTML5 数据属性。
回答by Praveen Chinthala
To quickly add dropdown
functionality to any element just add data-toggle="dropdown"
defined HTML5
data attribute, and any valid bootstrap dropdown
will automatically be activated.
要快速dropdown
向任何元素添加功能,只需添加data-toggle="dropdown"
定义的HTML5
数据属性,任何有效的引导程序dropdown
都会自动激活。