简体   繁体   中英

bootstrap styled alerts from javascript

Is it possible to create a bootstrap styled alert instead of the standard javascript alert? I have seen plugins like data-confirm-modal in rails that allow the confirm dialog to be styled instead of the standard javascript alert. However, I want to make every javascript alert in my app's code to be styled with bootstrap - is that possible? Either a dropin replacement like bootstrap_alert("Hello"); instead of alert("Hello"); or a way to style the default alert dialog with some bootstrap styles would work.

Since I am using rails, and the data-confirm-modal gem, I can use it from javascript as described here (from the docs ):

Given an element with data-confirm attributes in place, such as

<a id="foo" href="#" data-confirm="Really do this?" data-commit="Do it" data-cancel="Not really"/>

you can invoke .confirmModal() on it:

$('#foo').confirmModal();

Maybe create a div, style it as you desire and then make a bootstrap_alert js function that makes that div visible when called and dissapear when you click "Ok!" or whatever button you want into your alert.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM