in English

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

Gunakake .alert-linkkelas 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.

<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, mbutuhakeutil.js . Versi kompilasi kalebu iki.
  • Tambah tombol ngilangi lan .alert-dismissiblekelas, kang nambah padding ekstra ing sisih tengen tandha lan posisi .closetombol.
  • 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 .fadelan .showkelas.

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">&times;</span>
  </button>
</div>

Prilaku JavaScript

Pemicu

Aktifake ngilangi tandha liwat JavaScript:

$('.alert').alert()

Utawa kanthi dataatribut ing tombol ing tandha , kaya sing dituduhake ing ndhuwur:

<button type="button" class="close" data-dismiss="alert" aria-label="Close">
  <span aria-hidden="true">&times;</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 .fadelan .showana 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 closemetode 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...
})