博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
data-toggle data-target
阅读量:7123 次
发布时间:2019-06-28

本文共 2399 字,大约阅读时间需要 7 分钟。

data-toggle

I think you are a bit confused on the purpose of custom data attributes. From the

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.

By itself an attribute of data-toggle=value is basically a key-value pair, in which the key is "data-toggle" and the value is "value".

In the context of Bootstrap, the custom data in the attribute is almost useless without the context that their JavaScript library includes for the data. If you look at the non-minified version of then you can do a search for "data-toggle" and find how it is being used.

Here is an example of Bootstrap JavaScript code that I copied straight from the file regarding the use of "data-toggle".

  • Button Toggle

    Button.prototype.toggle = function () { var changed = true var $parent = this.$element.closest('[data-toggle="buttons"]') if ($parent.length) { var $input = this.$element.find('input') if ($input.prop('type') == 'radio') { if ($input.prop('checked') && this.$element.hasClass('active')) changed = false else $parent.find('.active').removeClass('active') } if (changed) $input.prop('checked', !this.$element.hasClass('active')).trigger('change') } else { this.$element.attr('aria-pressed', !this.$element.hasClass('active')) } if (changed) this.$element.toggleClass('active')

    }

The context that the code provides shows that Bootstrap is using the data-toggle attribute as a custom query selector to process the particular element.

From what I see these are the data-toggle options:

  • collapse
  • dropdown
  • modal
  • tab
  • pill
  • button(s)

You may want to look at the to get more specifics of what each do, but basically the data-toggle attribute toggles the element to active or not.

 

data-target

data-target is used by bootstrap to make your life easier. You (mostly) do not need to write a single line of Javascript to use their pre-made .

The data-target attribute should contain a CSS selector that points to the HTML Element that will be changed.

:

In this example, the button has data-target="#myModal", if you click on it, <div id="myModal">...</div> will be modified (in this case faded in). This happens because #myModal in CSS selectors points to elements that have an id attribute with the myModal value.

Further information about the HTML5 "data-" attribute:

 

转载地址:http://ycael.baihongyu.com/

你可能感兴趣的文章
刷blos
查看>>
centos升级新内核所遇问题。
查看>>
win7 下安装 iis7.5+php5.3的配置方法(图文)
查看>>
SQL语句学习之路10
查看>>
[用事实说明两个凡是]一个mysql莫名锁表的问题
查看>>
ubuntu设置静态IP
查看>>
hql select from与from 的区别
查看>>
wxPython之Socket客户端
查看>>
linux系统目录结构详解(简单易懂)
查看>>
学习《Effective C++》
查看>>
CS224n笔记9 机器翻译和高级LSTM及GRU
查看>>
KVM虚拟机
查看>>
GdiPlus[57]: 图像(九) IGPBitmap 特有的属性与方法
查看>>
Windows 多媒体函数(winmm.dll 中的函数)汇总
查看>>
关于 Delphi 中流的使用(4) 遍历读取流中的所有数据
查看>>
使用 IntraWeb (4) - 页面布局之 TIWRegion
查看>>
域控的升级及客户端加入域
查看>>
【Java每日一题】20161129
查看>>
[译文]greenlet:轻量级并发程序
查看>>
五分钟学会HTML
查看>>