如何设置JavaScript警报框的宽度和高度?

How I can set the width and height of a JavaScript alert box?

要在JavaScript中设置警报框的宽度和高度,您需要使用自定义警报框。 此警报框的样式为CSS。

使用以下代码(使用JavaScript库jQuery)设置警报框的宽度和高度:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!DOCTYPE html>
<html>
 <head>
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
   
   
    function functionAlert(msg, myYes)
    {
      var confirmBox = $("#confirm");
      confirmBox.find(".message").text(msg);
      confirmBox.find(".yes").unbind().click(function()
      {
       confirmBox.hide();
      });
      confirmBox.find(".yes").click(myYes);
      confirmBox.show();
    }
   
   <style>
    #confirm
    {
      display: none;
      background-color: #F3F5F6;
      color: #000000;
      border: 1px solid #aaa;
      position: fixed;
      width: 300px;
      height: 100px;
      left: 50%;
      margin-left: -100px;
      padding: 10px 20px 10px;
      box-sizing: border-box;
      text-align: center;
    }
    #confirm button {
      background-color: #FFFFFF;
      display: inline-block;
      border-radius: 12px;
      border: 4px solid #aaa;
      padding: 5px;
      text-align: center;
      width: 60px;
      cursor: pointer;
    }
    #confirm .message
    {
      text-align: left;
    }
   </style>
 </head>
 <body>
   
    This is a warning message.
    <button class="yes">OK</button>
   
   <input type="button" value="Click Me" onclick="functionAlert();" />
 </body>
</html>