html - 什么是 data-target 和 data-slide-to 属性?

标签 html css twitter-bootstrap frontend

我正在使用 bootstrap,(好吧,我是新手),我发现了这两个属性,有人可以给我解释一下吗?

最佳答案

只是为了发扬@Larsenal 的观点,自定义数据属性对于开发人员来说可能非常方便。正如规范所说:

Custom data attributes are intended to store custom data private to the page or application, for which there are no more appropriate attributes or elements. These attributes are not intended for use by software that is independent of the site that uses the attributes.

示例用法包括:

存储初始高度/宽度,稍后可能会被 JS 更改。 通过 JavaScript 获取和设置这些属性的方法很简单 - 使用 getAttributesetAttribute

 <div id='strawberry-plant' data-fruit='12'></div>
 <script>
    // 'Getting' data-attributes using getAttribute
    var plant = document.getElementById('strawberry-plant');
    var fruitCount = plant.getAttribute('data-fruit'); // fruitCount = '12'
 </script>

记住,这不是 好的做法。因此,请使用数据集属性

在这里阅读更多关于数据属性的信息:http://html5doctor.com/html5-custom-data-attributes/

作为 JavaScript 开发人员,您会爱上它们(也可能不会)。

关于html - 什么是 data-target 和 data-slide-to 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19846686/

相关文章:

javascript - 使用 JavaScript 删除下一个 div,无需 jquery

javascript - 使用 Firefox 扩展插入 CSS

jquery - 如果没有 div 高度,Fuel UX 的无限滚动将无法工作

c# - Angular Controller 未被调用

html - 页脚在移动设备上显示不正确

javascript - Angular 2 - 根据页面切换指令组件

html - 在段落结束后添加分隔符图像

html - 在 div 中彼此相邻

html - 中心 ul-nav [ Bootstrap 选项卡]

html - 如何将Facebook分享门添加到Youtube视频