如何创建 CSS 并将其应用于 javascript Alert

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2565035/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 00:56:20  来源:igfitidea点击:

How to create and apply CSS to javascript Alert

javascriptcssalert

提问by Dr. Rajesh Rolen

Please tell me, how to apply CSS on javascript Alert. Thanks

请告诉我,如何在 javascript Alert 上应用 CSS。谢谢

回答by Sasha Chedygov

You cannot. alert()simply shows a native message box, so it'll look however the OS makes it look.

你不能。alert()只是显示一个本机消息框,所以它会看起来像操作系统使它看起来一样。

In general, you shouldn't be using alert boxes because they are annoying and they block the entire browser.* You could always create a fake alert box with JavaScript that achieves the same effect. You could then style it however you want with normal CSS. If you use jQuery, there's SimpleModal(demos).

一般来说,您不应该使用警告框,因为它们很烦人,并且会阻塞整个浏览器。* 您始终可以使用 JavaScript 创建一个假警告框,以实现相同的效果。然后,您可以使用普通 CSS 随意设置样式。如果您使用 jQuery,则可以使用SimpleModal( demos)。

* Modern browsers tend to only block the window that spawned the alert, but they're still annoying and you still shouldn't use them. :)

* 现代浏览器往往只会阻止产生警报的窗口,但它们仍然很烦人,您仍然不应该使用它们。:)

回答by Ming-Tang

It is not possible, or else people will use it to phish.

这是不可能的,否则人们会用它来钓鱼。

回答by slier

you might want to check jConfirm (jQuery plugin)

你可能想检查 jConfirm(jQuery 插件)

http://abeautifulsite.net/2008/12/jquery-alert-dialogs/

http://abeautifulsite.net/2008/12/jquery-alert-dialogs/

回答by o.k.w

No you can't do that. I would suggest you either let it be, or use a modal window. You can also try using modal/dialog plugins e.g. http://docs.jquery.com/UI/Dialog

不,你不能那样做。我建议你要么顺其自然,要么使用模态窗口。您也可以尝试使用模态/对话框插件,例如http://docs.jquery.com/UI/Dialog

回答by Shamsher Sidhu

You can use the sweet alert library of js

你可以使用js的sweet alert库

official website

官方网站

github

github

You can also customize the alerts with simple CSS.

您还可以使用简单的 CSS 自定义警报。