本文已经不推荐在使用了,有更加优秀的 ,详情参考layui弹出层
前端当前页面编辑一些数据时,往往会用到弹出窗口,但每个页面单独修改有显得比较麻烦,因此,可以建立一个公用的方法,去掉用就可以了;
先上效果图
上图就是效果图,如果不是你想找的类型,请绕道。
1.创建方法
- function OpenDetial(id, url, title, width, height) {
- debugger;
- var _srcWidth = parseInt(screen.width);
- var _srcHeight = parseInt(screen.height);
- _width = parseInt(width) || _srcWidth;
- _height = parseInt(height) || _srcHeight;
-
- var cssWidth = width == undefined ? "100%" : _width;
- var cssHeight = height == undefined ? "100%" : _height;
-
- var left = (_srcWidth - _width) == 0 ? 0 : ((_srcWidth - _width) / 2 - 300);
- var top = (_srcHeight - _height) == 0 ? 0 : ((_srcHeight - _height) / 2 - 100);
-
-
- var _id = "#" + id;
- var close = "CloseDetial('" + id + "')";
- var detial =
- ''
- + ''
- + ''
- + ' '
- + '';
- $(_id).html(detial);
- $("#title").html(title);
- $(_id).css({ "display": "none", "position": "absolute", "bottom": "10px", "width": "100%", "top": "2px", "height": "96%", "background-color": "rgba(223, 236, 236, 0.36)"});
- $("#panel").css({ "width": cssWidth, "height": cssHeight, "left": left, "top": top, "position": "absolute", "border": "1px solid #22acac", "opacity": "1", "background-color": "white" });
- $("#detialForm").attr("src", url);
- $(_id).slideDown();
-
-
- }
-
- function CloseDetial(id) {
- debugger;
- $("#"+id.trim()).slideUp();
- }
2.页面调用
-
- <script src="/Themes/Scripts/jquery-1.8.2.min.js" type="text/javascript">script>
- <script type="text/javascript">
- function add() {
- var url = "/SysBase/SysUser/UserInfo_form.aspx";
- OpenDetial("UserEdit", url, "用户信息 - 添加", 700, 500); //调用方法
- }
- script>
- head>
- <body>
-
- <div id="UserEdit">div>
- body>
-
- <script src="/Themes/Scripts/jquery-1.8.2.min.js" type="text/javascript">script>
- <script type="text/javascript">
- function add() {
- var url = "/SysBase/SysUser/UserInfo_form.aspx";
- OpenDetial("UserEdit", url, "用户信息 - 添加", 700, 500); //调用方法
- }
- script>
- head>
- <body>
-
- <div id="UserEdit">div>
- body>
3.附件图片