如何更改警报框的样式?

2022-08-30 03:00:56

我需要更改警报框中“确定”按钮的样式。

<head>
    <script type="text/javascript">
        function show_alert() {
            alert("Hello! I am an alert box!");
        }
    </script>
</head>
<body>
    <input type="button" onclick="show_alert()" value="Show alert box" />
</body>

答案 1

警报框是一个系统对象,不受 CSS 的约束。要做这种风格的事情,你需要创建一个HTML元素并模仿功能。jQuery UI对话框为您做了很多工作,基本上就像我描述的那样工作:链接alert()

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Dialog - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#dialog" ).dialog();
  } );
  </script>
</head>
<body>
 
<div id="dialog" title="Basic dialog">
  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
 
 
</body>
</html>

答案 2

我使用SweetAlert这真是太棒了,您将获得许多自定义选项以及所有回调

Screenshot

swal("Here's a message!", "It's pretty, isn't it?");

enter image description here