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.

Modal Example Code from BS3:

<!-- 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的更多相关文章

  1. USB DATA Toggle

    For bulk and interrupt transfers, the data toggle resets <0> only on Set Configuration, Set In ...

  2. 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 ...

  3. $.data()、$().data

    两个方法很相似,但是有区别,简单说一下: $.data():jq的静态方法,也就是jQuery.data()直接调用 $().data():实例方法,先有实例,才能调用这个方法,例如:$(" ...

  4. Data truncation: Data too long for column 'gender' at row 1 出现的原因

    创建数据库的代码如下: create database day15 ; use day15 ; create table customer( id varchar(100) primary key, ...

  5. 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 ...

  6. Data truncation: Data too long for column 'content' at row 1

    项目运行报错: Data truncation: Data too long for column 'content' at row 1 是由于字段长度太小导致的 搜索mysql 中text 字段长度 ...

  7. 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 ...

  8. $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= ...

  9. 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 ...

  10. 数据库报错com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'ua' at row 1

    记一次报错记录,成长路上的点滴 明明使用浏览器或者微信开发工具调试接口没有问题,但是在真机测试时候就出问题了.(((¬_¬)) 500服务器内部错误,要死的节奏啊 登陆tomcat服务器 使用命令ta ...

随机推荐

  1. 20181225模拟赛 T1 color (转化思想,分拆思想)

    题目: 有⼀块有 n 段的栅栏,要求第 i 段栅栏最终被刷成颜色 ci .每⼀次可以选择 l, r 把第l . . . r 都刷成某种颜色,后刷的颜⾊会覆盖之前的.⼀共有 m 种颜色,雇主知道只需要用 ...

  2. Visual Studio 2013/2015/2017快捷键(转载)

    本文为转载文章,原文:[心存善念]  [Fonour] 项目相关的快捷键 Ctrl + Shift + B = 生成项目 Ctrl + Alt + L = 显示 Solution Explorer(解 ...

  3. sscanf,sprintf

    sprintf函数 sprintf函数原型为 int sprintf(char str, const char format, ...).作用是格式化字符串,具体功能如下所示: 将数字变量转换为字符串 ...

  4. 在 Sublime Text 直接运行 Javascript 调试控制台

    转载自:http://www.jianshu.com/p/43b0726792f7 sublime text javascript Sublime Text是深受喜欢的多语言编辑器,很多开发人员都选择 ...

  5. jsp获取绝对路径----${pageContext.request.contextPath}

    JSP取得绝对路径 在JavaWeb开发中,常使用绝对路径的方式来引入JavaScript和CSS文件,这样可以避免因为目录变动导致引入文件找不到的情况,常用的做法如下: 一.使用${pageCont ...

  6. C# 3.0特性

    C# 3.0的扩展特性主要包括以下几点,我们在后面也会按照这个顺序进行介绍:1.隐式局部变量(implicitly typed local variables),通过初始化该局部变量的表达式自动推断出 ...

  7. HDU-1272小希的迷宫,并查集?其实不用并查集;

    小希的迷宫                                                                                               ...

  8. 【转】Java的path,classpath,java_home环境变量的配置与具体含义

    对于一个Java初学者来说,第一步要做的是安装jdk并配置环境变量,一般按照书上或者网上的步骤,一步步照着做就行了,但是对于初学者来说,很多问题没有解决,比如为什么很多配置方法各不相同,却都能够配置成 ...

  9. Linux下C编程入门(1)

    Linux系统的介绍(以下以Manjaro最新版为例子): 一.系统的安装: 1.可以直接使用U盘做一个live usb的启动盘,在bios中设置从U盘启动即可拥有linux系统,如果是新式bios需 ...

  10. LOAP& its implimenlation

    LDAP 概念 LDAP的英文全称是Lightweight Directory Access Protocol,简称为LDAP,LDAP是轻量目录访问协议,LDAP是轻量目录访问协议.简单的说来,LD ...