data-toggle data-target
data-toggle
https://stackoverflow.com/questions/30629974/how-does-the-data-toggle-attribute-work-whats-its-api
I think you are a bit confused on the purpose of custom data attributes. From the w3 spec
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 bootstrap.js 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 Bootstrap JavaScript documentation to get more specifics of what each do, but basically the data-toggle attribute toggles the element to active or not.
data-target
https://stackoverflow.com/questions/21944735/what-is-the-data-target-attribute-in-bootstrap-3
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 JavaScript components.
The data-target attribute should contain a CSS selector that points to the HTML Element that will be changed.
<!-- Button trigger modal -->
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
[...]
</div>
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: https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_data_attributes
data-toggle data-target的更多相关文章
- USB DATA Toggle
For bulk and interrupt transfers, the data toggle resets <0> only on Set Configuration, Set In ...
- jmeter "you cannot switch bacause data cannot be converted to target Tab data,empty data to switch"报错
jmeter "you cannot switch bacause data cannot be converted to target Tab data,empty data to swi ...
- $.data()、$().data
两个方法很相似,但是有区别,简单说一下: $.data():jq的静态方法,也就是jQuery.data()直接调用 $().data():实例方法,先有实例,才能调用这个方法,例如:$(" ...
- Data truncation: Data too long for column 'gender' at row 1 出现的原因
创建数据库的代码如下: create database day15 ; use day15 ; create table customer( id varchar(100) primary key, ...
- Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'content' a
1.错误描述 org.hibernate.exception.DataException: could not execute statement at org.hibernate.exception ...
- Data truncation: Data too long for column 'content' at row 1
项目运行报错: Data truncation: Data too long for column 'content' at row 1 是由于字段长度太小导致的 搜索mysql 中text 字段长度 ...
- error: 'Can't connect to local MySQL server through socket '/data/3307/data/mysql.sock' (2)'
centos7.5 重启mysql报错 问题: [root@db01-51 ~]# mysqladmin -uroot -p123 -S /data/3307/data/mysql.sock shut ...
- $data[$i++]+=2;不等于$data[$i++]=$data[$i++]+2;
$data=array(1,2,3,4); $i=1; $data[$i++]+=2; var_dump($data); echo $i; //输出:array(1,4,3,4) 和 2 $data= ...
- Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'img' at row 1故障
Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'img' at ro ...
- 数据库报错com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'ua' at row 1
记一次报错记录,成长路上的点滴 明明使用浏览器或者微信开发工具调试接口没有问题,但是在真机测试时候就出问题了.(((¬_¬)) 500服务器内部错误,要死的节奏啊 登陆tomcat服务器 使用命令ta ...
随机推荐
- [Luogu] P1865 A % B Problem
题目描述 区间质数个数 输入输出格式 输入格式: 一行两个整数 询问次数n,范围m 接下来n行,每行两个整数 l,r 表示区间 输出格式: 对于每次询问输出个数 t,如l或r∉[1,m]输出 Cros ...
- elementui 后台管理系统遇到的问题(二) 树形控件 el-tree
elementui中树形控件的使用 一.将后台返回的数据填充到前端控件中,需要注意的几点问题 (1).el-tree中需要绑定node-key='自定义的id名称' (2).在配置data中defau ...
- nginx网站标准配置
#nginx开启的进程数worker_processes 4; #4核CPU #定义全局错误日志定义类型,[debug|info|notice|warn|crit]error_log ...
- DB2隔离级别
四.隔离级别与锁 数据库是利用锁和隔离级别来共同处理数据库的并发的.DB2数据库用来尝试实施并发性的方法之一是通过使用隔离级别,它决定在第一个事务访问数据时,如何对其他事务锁定或隔离该事务所使用的数据 ...
- Linux 关于umount
场景:linux下挂载过去的代码目录编译失败.怀疑本地磁盘空间不足问题导致.解决方法:卸载重新挂载. 操作:卸载时报错: 解决方法: 1.umount, 老是提示:device is busy, 服务 ...
- I2C详细介绍
I2C时序 1.开始和停止: 说明: 开始:在SCL的高电平的时候SDA线的从高电平到低电平的跳变定义为开始 停止:在SCL的高电平的时候SDA线的从低电平到高电平的跳变定义为停止 2.有效数据的位置 ...
- [luoguP2617] Dynamic Ranking(树状数组 套 主席树 + 离散化)
传送门 BZOJ上是权限题,洛谷赞啊. 求区间 K 大数很简单. 但是如果修改某个数的话,那么就得把这个数及后面所建的主席树都更新一遍 nlogn,显然不行. 所以可以在外面套一个树状数组来优化,树状 ...
- Big String(poj 2887)
题意: 给你一个不超过1e6的字符串,和不超过2000次的操作 操作分为两种: 1.将一个字符插入到某个位置的前面 2.询问当前位置的字符 /* 块状链表模板水题(我的智商也就能做这种题了). 观察题 ...
- hdu_1085_Holding Bin-Laden Captive!_201404261008
Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- CSS+Jquery实现QQ分组列表
实现效果图如下: 说明: 1.css隐藏分组下的好友内容: 2.Jquery实现点击分组项事件,实现好友内容的显示和隐藏: 3.样式1,可展开多个分组:样式2,只能有一个分组展开: 源码: <! ...