带有 CSS 的警报框 [英] Alert Box with CSS
本文介绍了带有 CSS 的警报框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以添加带有 CSS 属性的警报框?
Is it possible to add Alert box with CSS attributes?
对于我的代码
if (username==null) {
alert("Please Fill Up Required Field");
}
else {
XXX
}
我的警报样式代码
<style>
.alert {
padding: 20px;
background-color: #f44336;
color: white;
}
</style>
我想要的结果:https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_alert
但我总是得到这个:https://gyazo.com/88f00fdf2654367aa148b0263c
推荐答案
问题在于您正在使用 alert
功能:
The problem is you're using the alert
function:
alert("Please Fill Up Required Field");
您无法设置样式 - 它是浏览器生成的框.您需要使用模态框,然后您就可以对其进行样式设置.
You can't style this - it's a browser-generated box. You need to use a modal box, and then you can style it.
这篇关于带有 CSS 的警报框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文