彈出窗口,加載頁面。彈出窗口初始位置為居中。可在關閉窗口時,回調主頁面按鈕。要求jquery。
效果演示
首先,演示主窗口兩個按鈕作用。然后,演示關閉彈出窗口時,調用主窗口的兩個按鈕。
主要代碼(時間倉促,沒加注釋,不過代碼很簡單,就是創建幾個元素拼在一起,每個元素都用var=標明了)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
var _divMask; var _divBox; function ShowMask() { var divMask = $( '<div></div>' ) .attr( "id" , "divMask" ) .css({ "position" : "absolute" , "left" : "0" , "top" : "0" , "width" : "100%" , "height" : "100%" , "backgroundColor" : "gray" , "opacity" : "0.4" }).appendTo( "body" ); _divMask = divMask; return divMask; } function ShowBox(title, url, width, height) { ShowMask(); var divBox = $( "<div></div>" ) .attr( "id" , "divBox" ) .css({ "position" : "absolute" , "top" : (($(document).height() - height) / 2) < 0 ? 0 : (($(document).height() - height) / 2), "left" : (($(document).width() - width) / 2), "width" : width, "height" : height, "border" : "2px solid gray" , "backgroundColor" : "white" }) .appendTo( "body" ); var pTitle = $( "<p></p>" ) .css({ "width" : (width - 20) / 2, "float" : "left" , "padding" : "5px" , "margin" : "0" }) .text(title) .appendTo(divBox); var pClose = $( "<p></p>" ) .css({ "width" : (width - 20) / 2, "float" : "left" , "text-align" : "right" , "padding" : "5px" , "margin" : "0" }) .appendTo(divBox); var aClose = $( "<a></a>" ) .css({ "color" : "black" , "text-decoration" : "none" }) .attr( "href" , "javascript:CloseBox();" ) .text( "關 閉" ) .appendTo(pClose); var hr = $( "<hr/>" ) .css({ "margin" : "0" , "border" : "1px solid gray" }) .appendTo(divBox); var iframeContainer = $( "<iframe></iframe>" ) .attr( "id" , "divContainer" ) .css({ "width" : width, "height" : height - 13 - pTitle.height(), "float" : "left" , "overflow" : "auto" , "border" : "0" }) .attr( "src" , url) .appendTo(divBox); _divBox = divBox; //divBox.draggable({ handle: "p" }); } function CloseBox(btn) { if (_divMask == null ) { if (btn != null && btn != '' ) { parent.document.getElementById(btn).click(); } $(parent.document.getElementById( "divMask" )).remove(); $(parent.document.getElementById( "divBox" )).remove(); } else { _divMask.remove(); _divBox.remove(); } } |
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:https://www.cnblogs.com/David-Huang/p/3869293.html