Gara qabiyyee ijootti darbi Gara docs navigationitti darbi
in English

JaavaScript

Bootstrap gara jireenyaatti fidaa filannoo JavaScript plugins keenyaan. Waa'ee tokkoon tokkoo pilaaginii, filannoowwan API deetaa fi sagantaa keenyaa fi kkf baradhu.

Dhuunfaa ykn qindaa’ee

Plugins dhuunfaan hammatamuu danda'u (Bootstrap's individual fayyadamuun js/dist/*.js), ykn hunda yeroo tokkotti fayyadamuun bootstrap.jsykn xiqqaate bootstrap.min.js(lamaanuu hin dabaliin).

Yoo bundler fayyadamte (Webpack, Rollup...), /js/dist/*.jsfaayiloota kanneen UMD qophaa'an fayyadamuu dandeessa.

Bootstrap akka moojuuliitti fayyadamuu

ESMBootstrap akka ( bootstrap.esm.jsfi ) tti ijaarame bootstrap.esm.min.jskan Bootstrap akka moojuuliitti biraawzari keessan keessatti akka fayyadamtan isin dandeessisu ni kennina, yoo biraawzaroota keessan irratti xiyyeeffatan yoo deeggaran .

<script type="module">
  import { Toast } from 'bootstrap.esm.min.js'

  Array.from(document.querySelectorAll('.toast'))
    .forEach(toastNode => new Toast(toastNode))
</script>

Pilaginoota wal hin simne

Sababa daangeffama browser irraa kan ka'e, plugins keenya tokko tokko, jechuunis Dropdown, Tooltip fi Popover plugins, Popper irratti waan hirkataniif <script>tag type qabu keessatti fayyadamuun hin danda'amu. moduleOdeeffannoo dabalataa waa'ee dhimmichaa asii ilaalaa .

Hirkatummaa

Plugins fi qaamolee CSS tokko tokko plugins biroo irratti hundaa'u. Yoo dhuunfaan ifteessitoota hammatte, hirkattummaa kana docs keessatti ilaaluu mirkaneessi.

Dropdowns, popovers fi tooltipps keenyas Popper irratti hundaa'u .

Ammas jQuery fayyadamuu barbaadduu? Ni danda'ama!

Bootstrap 5 jQuery malee akka fayyadamtuuf kan qophaa'e yoo ta'u, garuu ammallee jQuery waliin qaamolee keenya fayyadamuun ni danda'ama. Yoo Bootstrap wanta jQuerykeessattiwindow arge qaamolee keenya hunda sirna plugin jQuery keessatti ni dabala; kana jechuun gorsa meeshaalee dandeessisuuf gochuu ni $('[data-bs-toggle="tooltip"]').tooltip()dandeessa jechuudha. Qaamolee keenya kanneen biroonis akkasuma.

Amaloota deetaa

Ijaarsiin Bootstrap hundi jechuun ni danda'ama karaa HTML qofa amaloota deetaa waliin dandeessisuun fi qindaa'uu danda'u (karaa keenya filatamaan hojii JavaScript fayyadamuu). Tuuta amaloota deetaa tokko qofa qaama tokko irratti fayyadamuu kee mirkaneessi (fkn, gorsa meeshaa fi moodaalii qaree walfakkaataa irraa kakaasuu hin dandeessu.)

Filattoota

Yeroo ammaa qaamolee DOM gaafachuuf malawwan dhalootaa querySelectorfi querySelectorAllsababa raawwiif fayyadamna, kanaaf filattoota sirrii fayyadamuu qabda . Yoo filannoowwan addaa fayyadamte, fakkeenyaaf: collapse:Exampleisaan jalaa miliquu kee mirkaneessi.

Taateewwan

Bootstrap taateewwan amala gochoota addaa plugins baay'eedhaaf kenna. Walumaagalatti, kunniin bifa xumura hin qabnee fi gocha darbeen dhufu - bakka xumura hin qabne (fkn show) jalqaba taatee tokkoo irratti kaka’u, fi bifa gocha isaa darbe (fk. shown) xumura gocha tokkoo irratti kaka’u.

Taateewwan dhuma hin qabne hundi preventDefault()dalagaa ni kennu. Kunis dandeettii raawwii gocha tokkoo osoo hin jalqabin dhaabuu kenna. Qabduu taatee irraa soba deebisuun ofumaan ni waama preventDefault().

var myModal = document.getElementById('myModal')

myModal.addEventListener('show.bs.modal', function (event) {
  if (!data) {
    return event.preventDefault() // stops modal from being shown
  }
})

jTaateewwan gaaffii

Bootstrap jQuery yoo wanta jQuerykeessatti argamee fi amalli . Yoo jQuery argame, Bootstrap taateewwan galata sirna taatee jQuery'f ni baafata. Kanaafuu yoo taateewwan Bootstrap dhaggeeffachuu barbaadde, maloota jQuery ( , ) osoo hin taane fayyadamuu qabda .windowdata-bs-no-jquery<body>.on.oneaddEventListener

$('#myTab a').on('shown.bs.tab', function () {
  // do something...
})

API sagantaa

Ijaarsitoonni hundi wanta filannoo filannoo ykn homaa hin fudhatu (kan amala durtii isaatiin ifteessituu jalqaba):

var myModalEl = document.getElementById('myModal')

var modal = new bootstrap.Modal(myModalEl) // initialized with defaults
var modal = new bootstrap.Modal(myModalEl, { keyboard: false }) // initialized with no keyboard

Yoo fakkeenya ifteessaa murtaa'e argachuu barbaadde, tokkoon tokkoon ifteessaa getInstancemala tokko saaxila. Kallattiin elementii tokko irraa argachuuf, akkas godhi: bootstrap.Popover.getInstance(myPopoverEl).

Filattoota CSS ijaarsitoota keessatti

Akkasumas filannoo CSS akka murfii jalqabaatti bakka qaama DOM fayyadamuun ifteessaa jalqabsiisuu dandeessa. Yeroo ammaa elementiin plugin'f querySelectormalaan argama erga plugins keenya elementii tokko qofa deeggaru.

var modal = new bootstrap.Modal('#myModal')
var dropdown = new bootstrap.Dropdown('[data-bs-toggle="dropdown"]')

Faankishiniiwwanii fi ce'umsawwan wal hin simne

Malleen API sagantaa hundi wal hin simne yoo ta'an erga ce'umsi jalqabame garuu osoo hin xumuramin gara waamichaatti deebi'u .

Erga ce'umsi xumuramee booda gocha tokko raawwachuuf, taatee walgitu dhaggeeffachuu dandeessa.

var myCollapseEl = document.getElementById('myCollapse')

myCollapseEl.addEventListener('shown.bs.collapse', function (event) {
  // Action to execute once the collapsible area is expanded
})

Dabalataan waamichi malaa qaama ce'umsaa irratti ni tuffatama .

var myCarouselEl = document.getElementById('myCarousel')
var carousel = bootstrap.Carousel.getInstance(myCarouselEl) // Retrieve a Carousel instance

myCarouselEl.addEventListener('slid.bs.carousel', function (event) {
  carousel.to('2') // Will slide to the slide 2 as soon as the transition to slide 1 is finished
})

carousel.to('1') // Will start sliding to the slide 1 and returns to the caller
carousel.to('2') // !! Will be ignored, as the transition to the slide 1 is not finished !!

Sajoo durtii

Sajoo durtii ifteessaa jijjiiruu dandeessa Constructor.Defaultwanta ifteessaa fooyyessuudhaan:

// changes default for the modal plugin's `keyboard` option to false
bootstrap.Modal.Default.keyboard = false

Waldhabdee hin qabu (yoo jQuery fayyadamte qofa)

Yeroo tokko tokko Bootstrap plugins UI frameworks biroo wajjin fayyadamuun barbaachisaadha. Haalota kanneen keessatti, walitti bu'iinsi iddoo maqaa darbee darbee uumamuu danda'a. Yoo kun ta'e, .noConflictpilaaginii gatii isaa deebisuu barbaaddu waamu dandeessa.

var bootstrapButton = $.fn.button.noConflict() // return $.fn.button to previously assigned value
$.fn.bootstrapBtn = bootstrapButton // give $().bootstrapBtn the Bootstrap functionality

Lakkoofsa version

VERSIONVershiniin tokkoon tokkoon pilaaginii Bootstrap karaa qabeentaa ijaarsa ifteessaa argachuun ni danda'ama . Fakkeenyaaf, plugin tooltip tiif:

bootstrap.Tooltip.VERSION // => "5.0.2"

Yeroo JaavaScript hanqifamu kufaatii addaa hin jiru

Bootstrap's plugins addatti yeroo JavaScript hanqifamu gracefully duubatti hin kufan. Yoo waa'ee muuxannoo fayyadamaa haala kana keessatti dhimmamte, <noscript>haala (fi akkaataa JaavaScript irra deebitee dandeessiftu) fayyadamtoota keetiif ibsuuf fayyadami, fi/ykn kufaatii amala mataa keetii itti dabali.

Manneen kitaabaa qaama sadaffaa

Bootstrap mana kitaabaa JaavaScript qaama sadaffaa akka Prototype ykn jQuery UI ifatti hin deeggaru. Taateewwan jiraatanis .noConflictfi maqaa addaan baafaman, rakkoon walsimsiisaa kan ofii keetiin sirreessuu qabdu jiraachuu danda'a.

Saanitaayizarii

Tooltips fi Popovers filannoowwan HTML fudhatan qulqulleessuuf sanitizer keenya ijaarame fayyadamu.

Gatiin durtii allowListkan armaan gadiiti:

var ARIA_ATTRIBUTE_PATTERN = /^aria-[\w-]*$/i
var DefaultAllowlist = {
  // Global attributes allowed on any supplied element below.
  '*': ['class', 'dir', 'id', 'lang', 'role', ARIA_ATTRIBUTE_PATTERN],
  a: ['target', 'href', 'title', 'rel'],
  area: [],
  b: [],
  br: [],
  col: [],
  code: [],
  div: [],
  em: [],
  hr: [],
  h1: [],
  h2: [],
  h3: [],
  h4: [],
  h5: [],
  h6: [],
  i: [],
  img: ['src', 'srcset', 'alt', 'title', 'width', 'height'],
  li: [],
  ol: [],
  p: [],
  pre: [],
  s: [],
  small: [],
  span: [],
  sub: [],
  sup: [],
  strong: [],
  u: [],
  ul: []
}

Yoo gatiiwwan haaraa durtii kana irratti dabaluu barbaadde allowListkanneen armaan gadii gochuu dandeessa:

var myDefaultAllowList = bootstrap.Tooltip.Default.allowList

// To allow table elements
myDefaultAllowList.table = []

// To allow td elements and data-bs-option attributes on td elements
myDefaultAllowList.td = ['data-bs-option']

// You can push your custom regex to validate your attributes.
// Be careful about your regular expressions being too lax
var myCustomRegex = /^data-my-app-[\w-]+/
myDefaultAllowList['*'].push(myCustomRegex)

Yoo sanitizer keenya bira darbuu barbaadde sababiin isaas mana kitaabaa addaa fayyadamuu filatte, fakkeenyaaf DOMPurify , kanneen armaan gadii gochuu qabda:

var yourTooltipEl = document.getElementById('yourTooltip')
var tooltip = new bootstrap.Tooltip(yourTooltipEl, {
  sanitizeFn: function (content) {
    return DOMPurify.sanitize(content)
  }
})