Tandha
Nyedhiyani pesen umpan balik kontekstual kanggo tumindak pangguna sing khas kanthi sawetara pesen tandha sing kasedhiya lan fleksibel.
Tuladha
Tandha kasedhiya kanggo teks apa wae, uga tombol ngilangi opsional. Kanggo gaya sing tepat, gunakake salah siji saka wolung kelas kontekstual sing dibutuhake.alert-success
(contone, ). Kanggo ngilangi inline, gunakake tandha plugin jQuery .
<div class="alert alert-primary" role="alert">
A simple primary alert—check it out!
</div>
<div class="alert alert-secondary" role="alert">
A simple secondary alert—check it out!
</div>
<div class="alert alert-success" role="alert">
A simple success alert—check it out!
</div>
<div class="alert alert-danger" role="alert">
A simple danger alert—check it out!
</div>
<div class="alert alert-warning" role="alert">
A simple warning alert—check it out!
</div>
<div class="alert alert-info" role="alert">
A simple info alert—check it out!
</div>
<div class="alert alert-light" role="alert">
A simple light alert—check it out!
</div>
<div class="alert alert-dark" role="alert">
A simple dark alert—check it out!
</div>
Nuduhake makna kanggo teknologi assistive
Nggunakake warna kanggo nambah makna mung menehi indikasi visual, sing ora bakal dikirim menyang pangguna teknologi bantu - kayata pembaca layar. Priksa manawa informasi sing dituduhake kanthi warna katon jelas saka isi kasebut (umpamane teks sing katon), utawa kalebu liwat cara alternatif, kayata teks tambahan sing didhelikake karo .sr-only
kelas.
Warna link
Gunakake .alert-link
kelas sarana kanggo nyedhiyakake link warna sing cocog kanthi cepet ing tandha apa wae.
<div class="alert alert-primary" role="alert">
A simple primary alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
</div>
<div class="alert alert-secondary" role="alert">
A simple secondary alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
</div>
<div class="alert alert-success" role="alert">
A simple success alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
</div>
<div class="alert alert-danger" role="alert">
A simple danger alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
</div>
<div class="alert alert-warning" role="alert">
A simple warning alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
</div>
<div class="alert alert-info" role="alert">
A simple info alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
</div>
<div class="alert alert-light" role="alert">
A simple light alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
</div>
<div class="alert alert-dark" role="alert">
A simple dark alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
</div>
Isi tambahan
Tandha uga bisa ngemot unsur HTML tambahan kaya judhul, paragraf lan pemisah.
Inggih rampung!
Aww ya, sampeyan kasil maca pesen tandha penting iki. Teks conto iki bakal mlaku rada suwe supaya sampeyan bisa ndeleng kepiye jarak ing tandha bisa digunakake karo konten kaya iki.
Yen perlu, manawa sampeyan nggunakake utilitas margin kanggo njaga barang-barang sing apik lan rapi.
<div class="alert alert-success" role="alert">
<h4 class="alert-heading">Well done!</h4>
<p>Aww yeah, you successfully read this important alert message. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.</p>
<hr>
<p class="mb-0">Whenever you need to, be sure to use margin utilities to keep things nice and tidy.</p>
</div>
Ngilangi
Nggunakake plugin JavaScript tandha, sampeyan bisa ngilangi inline tandha. Mangkene carane:
- Priksa manawa sampeyan wis mbukak plugin tandha, utawa kompilasi Bootstrap JavaScript.
- Yen sampeyan lagi mbangun JavaScript saka sumber, mbutuhake
util.js
. Versi kompilasi kalebu iki. - Tambah tombol ngilangi lan
.alert-dismissible
kelas, kang nambah padding ekstra ing sisih tengen tandha lan posisi.close
tombol. - Ing tombol ngilangi, tambahake
data-dismiss="alert"
atribut, sing nyebabake fungsi JavaScript. Priksa manawa sampeyan nggunakake<button>
unsur kasebut kanggo tumindak sing bener ing kabeh piranti. - Kanggo animate tandha nalika ngilangi, manawa kanggo nambah
.fade
lan.show
kelas.
Sampeyan bisa ndeleng iki ing tumindak kanthi demo langsung:
<div class="alert alert-warning alert-dismissible fade show" role="alert">
<strong>Holy guacamole!</strong> You should check in on some of those fields below.
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
Prilaku JavaScript
Pemicu
Aktifake ngilangi tandha liwat JavaScript:
$('.alert').alert()
Utawa kanthi data
atribut ing tombol ing tandha , kaya sing dituduhake ing ndhuwur:
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
Elinga yen nutup tandha bakal nyopot saka DOM.
Metode
Metode | Katrangan |
---|---|
$().alert() |
Ndadekake tandha ngrungokake acara klik ing unsur turunan sing nduweni data-dismiss="alert" atribut. (Ora perlu nalika nggunakake inisialisasi otomatis data-api.) |
$().alert('close') |
Nutup tandha kanthi nyopot saka DOM. Yen kelas .fade lan .show ana ing unsur kasebut, tandha bakal ilang sadurunge dibusak. |
$().alert('dispose') |
Numpes tandha unsur. |
$('.alert').alert('close')
Acara
Plugin tandha Bootstrap nyedhiyakake sawetara acara kanggo nyambungake fungsi tandha.
Acara | Katrangan |
---|---|
close.bs.alert |
Acara iki langsung murub nalika close metode conto diarani. |
closed.bs.alert |
Acara iki dipecat nalika tandha wis ditutup (bakal ngenteni transisi CSS rampung). |
$('#myAlert').on('closed.bs.alert', function () {
// do something...
})