JavaScript
Nqa Bootstrap rau lub neej nrog peb xaiv JavaScript plugins ua rau jQuery. Kawm paub txog txhua lub plugin, peb cov ntaub ntawv thiab cov kev xaiv API programmatic, thiab lwm yam.
Tus kheej los yog muab tso ua ke
Plugins tuaj yeem suav nrog tus kheej (siv Bootstrap tus neeg js/dist/*.js
), lossis tag nrho ib zaug siv bootstrap.js
lossis cov minified bootstrap.min.js
(tsis suav ob qho tib si).
Yog tias koj siv lub pob (Webpack, Rollup…), koj tuaj yeem siv /js/dist/*.js
cov ntaub ntawv uas yog UMD npaj.
Kev vam meej
Qee cov plugins thiab CSS cov khoom nyob ntawm lwm cov plugins. Yog tias koj suav nrog plugins ib tus zuj zus, nco ntsoov xyuas cov kev vam meej hauv cov ntaub ntawv. Tsis tas li ntawd nco ntsoov tias tag nrho cov plugins nyob ntawm jQuery (qhov no txhais tau tias jQuery yuav tsum tau suav nrog ua ntej cov ntaub ntawv plugin). Nrog pebpackage.json
saib seb jQuery versions twg tau txais kev txhawb nqa.
Peb cov dropdowns, popovers thiab tooltips kuj nyob ntawm Popper.js .
Cov ntaub ntawv yam ntxwv
Yuav luag txhua Bootstrap plugins tuaj yeem qhib thiab teeb tsa los ntawm HTML ib leeg nrog cov ntaub ntawv cwj pwm (peb txoj kev nyiam siv JavaScript ua haujlwm). Nco ntsoov tsuas yog siv ib txheej ntawm cov ntaub ntawv tus cwj pwm ntawm ib lub caij (xws li, koj tsis tuaj yeem ua rau cov lus qhia thiab cov qauv ntawm tib lub pob.)
Txawm li cas los xij, hauv qee qhov xwm txheej nws yuav xav tau lov tes taw qhov kev ua haujlwm no. Txhawm rau lov tes taw cov ntaub ntawv tus cwj pwm API, unbind tag nrho cov xwm txheej ntawm daim ntawv teev npe nrog data-api
xws li:
Xwb, txhawm rau tsom ib lub plugin tshwj xeeb, tsuas yog suav nrog lub plugin lub npe ua lub npe chaw nrog rau cov ntaub ntawv-api namespace zoo li no:
Cov xaiv
Tam sim no los nug DOM cov ntsiab lus peb siv cov txheej txheem ib txwm ua querySelector
thiab querySelectorAll
rau kev ua haujlwm vim li cas, yog li koj yuav tsum siv cov neeg xaiv siv tau . Yog tias koj siv cov xaiv tshwj xeeb, piv txwv li: collapse:Example
nco ntsoov khiav lawv.
Cov xwm txheej
Bootstrap muab cov xwm txheej kev cai rau feem ntau plugins 'kev ua tshwj xeeb. Feem ntau, cov no tuaj nyob rau hauv ib daim ntawv infinitive thiab yav dhau los koom nrog - qhov twg qhov infinitive (ex. show
) yog tshwm sim thaum pib ntawm ib qho kev tshwm sim, thiab nws yav dhau los kev koom tes (ex. shown
) yog tshwm sim ntawm qhov ua tiav ntawm qhov kev txiav txim.
Tag nrho cov txheej xwm infinitive muab preventDefault()
functionality. Qhov no muab lub peev xwm los nres qhov kev txiav txim ua ntej nws pib. Rov qab tsis muaj tseeb los ntawm tus neeg saib xyuas kev tshwm sim kuj tseem yuav hu xov tooj preventDefault()
.
Programmatic API
Peb kuj ntseeg tias koj yuav tsum tuaj yeem siv tag nrho Bootstrap plugins nkaus xwb los ntawm JavaScript API. Tag nrho cov pej xeem APIs yog ib leeg, chainable txoj kev, thiab xa rov qab cov sau ua raws li.
Txhua txoj hauv kev yuav tsum lees txais qhov kev xaiv xaiv khoom, ib txoj hlua uas tsom rau ib txoj hauv kev, lossis tsis muaj dab tsi (uas pib lub plugin nrog tus cwj pwm tsis zoo):
Txhua lub plugin kuj nthuav tawm nws cov neeg tsim khoom nyoos ntawm cov Constructor
cuab yeej: $.fn.popover.Constructor
. Yog tias koj xav tau ib qho plugin tshwj xeeb, muab nws ncaj qha los ntawm lub caij: $('[rel="popover"]').data('popover')
.
Asynchronous muaj nuj nqi thiab kev hloov pauv
Txhua txoj kev API programmatic yog asynchronous thiab rov qab mus rau tus neeg hu thaum qhov kev hloov pauv pib tab sis ua ntej nws xaus .
Txhawm rau ua qhov kev txiav txim thaum qhov kev hloov pauv tiav, koj tuaj yeem mloog cov xwm txheej sib thooj.
Tsis tas li ntawd, ib txoj kev hu rau ib qho kev hloov pauv yuav raug ignored .
Default settings
Koj tuaj yeem hloov qhov chaw pib rau lub plugin los ntawm kev hloov kho lub plugin cov Constructor.Default
khoom:
Tsis muaj teeb meem
Qee lub sij hawm nws yog qhov tsim nyog los siv Bootstrap plugins nrog rau lwm qhov UI lub luag haujlwm. Hauv cov xwm txheej no, kev sib tsoo ntawm lub npe chaw tuaj yeem tshwm sim qee zaus. Yog tias qhov no tshwm sim, koj tuaj yeem hu .noConflict
rau lub plugin koj xav rov qab tus nqi ntawm.
Cov lej
Cov version ntawm txhua qhov ntawm Bootstrap's jQuery plugins tuaj yeem nkag tau los ntawm cov VERSION
cuab yeej ntawm plugin tus tsim. Piv txwv li, rau tooltip plugin:
Tsis muaj qhov cuam tshuam tshwj xeeb thaum JavaScript raug kaw
Bootstrap's plugins tsis poob rov qab tshwj xeeb zoo nkauj thaum JavaScript raug kaw. Yog tias koj mob siab txog cov neeg siv kev paub dhau los hauv qhov no, siv <noscript>
los piav qhia qhov xwm txheej (thiab yuav ua li cas rov qhib JavaScript) rau koj cov neeg siv, thiab / lossis ntxiv koj tus kheej cov kev cai poob qis.
Cov tsev qiv ntawv thib peb
Bootstrap tsis ua haujlwm txhawb nqa JavaScript cov tsev qiv ntawv thib peb xws li Prototype lossis jQuery UI. Txawm hais tias .noConflict
thiab cov xwm txheej muaj npe, tej zaum yuav muaj teeb meem kev sib raug zoo uas koj yuav tsum tau kho ntawm koj tus kheej.
Siv
Txhua Bootstrap's JavaScript cov ntaub ntawv nyob ntawm util.js
thiab nws yuav tsum tau suav nrog rau lwm cov ntaub ntawv JavaScript. Yog tias koj siv cov ntawv sau ua ke (lossis me me) bootstrap.js
, tsis tas yuav suav nrog qhov no - nws twb muaj lawm.
util.js
suav nrog cov khoom siv hluav taws xob thiab tus pab cuam yooj yim rau transitionEnd
cov xwm txheej nrog rau CSS kev hloov pauv emulator. Nws tau siv los ntawm lwm cov plugins los kuaj xyuas CSS kev hloov pauv kev txhawb nqa thiab txhawm rau ntes dai hloov pauv.