Latest web development tutorials

Bootstrap alert box

Box warning (Alert) message is mostly used to display information such as end users want a warning or confirmation message. Box with a warning (Alert) plug-in, you can add cancel (dismiss) function to all the warning message box.

usage

There are two ways you can enable a warning box to cancel (dismissal) function:

  • Through data attribute: by adding data API (Data API) to cancel the function, only need to add a button to turn off data-dismiss = "alert",it will automatically add functionality to turn off the warning box.
    <a class="close" data-dismiss="alert" href="#" aria-hidden="true">
    	& Times;
    </a>
    
  • By JavaScript: adding cancel functionality through JavaScript:
    $ ( ". Alert"). Alert ()
    

Examples

The following example demonstrates the use of a warning box (Alert) widget by data attribute usage.

Examples

<Div class = "alert alert-warning" > <A href = "#" class = "close" data-dismiss = "alert"> & times; </ A> <Strong> Warning! </ Strong> your network connection problem. </ Div>

try it"

The results are as follows:

Box warning (Alert) widget

Options

There are no options.

method

Here are some warning box (Alert) plug-in useful ways:

方法描述实例
.alert()该方法让所有的警告框都带有关闭功能。
$('#identifier').alert();
Close Method.alert('close')关闭所有的警告框。
$('#identifier').alert('close');
To enable animation when closed, make sure you add the.fade and .in class.

Examples

The following example demonstrates.alert () method:

Examples

<H3> warning box (Alert) widget alert () method </ h3> <Div id = "myAlert" class = "alert alert-success" > <A href = "#" class = "close" data-dismiss = "alert"> & times; </ a> <Strong> Success! </ Strong> the outcome is successful. </ Div> <Div id = "myAlert" class = "alert alert-warning" > <A href = "#" class = "close" data-dismiss = "alert"> & times; </ a> <Strong> Warning! </ Strong> your network connection problem. </ Div> <Script>
$ (Function () {$ ( ".close") click (function () {$ ( "#myAlert") alert ();..});});
</ Script> [/ mycode2] </ div> <br> <A target = "_blank" href = "/try/try.php?filename=bootstrap3-plugin-alert-method1" class = "tryitbtn"> try »</ a> </ Div> <P> The following example demonstrates the <b> .alert ( 'close' ) Usage </ b> Method: </ p> <Div class = "example"> <H2 class = "example"> instance </ h2> <Div class = "example_code"> [mycode3 type = "html"] <h3> warning box (Alert) widget alert ( 'close') method </ h3> <Div id = "myAlert" class = "alert alert-success" > <A href = "#" class = "close" data-dismiss = "alert"> & times; </ a> <Strong> Success! </ Strong> the outcome is successful. </ Div> <Div id = "myAlert" class = "alert alert-warning" > <A href = "#" class = "close" data-dismiss = "alert"> & times; </ a> <Strong> Warning! </ Strong> your network connection problem. </ Div> <Script>
$ (Function () {$ ( ".close") click (function () {$ ( "#myAlert") alert ( 'close');..});});
</ Script>

try it"

You can see all the warning box are applied off feature turns off any warning box, the other remaining alert box will be closed.

event

The following table lists the warning box (Alert) plug-ins to be used in the event. These events can be used when the hook function.

事件描述实例
close.bs.alert当调用close实例方法时立即触发该事件。
$('#myalert').bind('close.bs.alert', function () {
  // 执行一些动作...
})
closed.bs.alert当警告框被关闭时触发该事件(将等待 CSS 过渡效果完成)。
$('#myalert').bind('closed.bs.alert', function () {
	// 执行一些动作...
})

Examples

The following example demonstrates event box warning (Alert) plug-in:

Examples

<Div id = "myAlert" class = "alert alert-success" > <A href = "#" class = "close" data-dismiss = "alert"> & times; </ a> <Strong> Success! </ Strong> the outcome is successful. </ Div> <Script>
$ (Function () {$ ( "#myAlert"). Bind ( 'closed.bs.alert', function () { alert ( "warning message box is closed.");});});
</ Script>

try it"

The results are as follows:

Box warning (Alert) Plug-in Event