What is the `data-target` attribute in Bootstrap 3?

前端 未结 2 1521
春和景丽
春和景丽 2020-12-07 23:44

Can you tell me what is the system or behavior behind the data-target attribute used by Bootstrap 3?

I know that data-toggle used to aim API JavaScript

2条回答
  •  情书的邮戳
    2020-12-08 00:41

    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:

    
    
    
    
    
    

    In this example, the button has data-target="#myModal", if you click on it,

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

提交回复
热议问题