目的:弹出、关闭window。
效果图:
![](https://img.haomeiwen.com/i1522646/9a935aceced68aa5.jpg)
代码:
/EasyUiLearn/WebContent/window/index.jsp
<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath();%>
<%String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<base href="<%=basePath %>">
<title>window</title>
<!--
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.4.3/themes/default/easyui.css">
-->
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.4.3/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.4.3/themes/icon.css">
<script type="text/javascript" src="jquery-easyui-1.4.3/jquery.min.js"></script>
<script type="text/javascript" src="jquery-easyui-1.4.3/jquery.easyui.min.js"></script>
</head>
<script>
var windowMain = {
initWindow:function(){
$("#win").window({
title:"一个弹出窗口",
width:600,
height:400,
modal:true,
closed:true,
href:"window/window.jsp",
onLoad:function(){
console.log('页面加载完成调用!');
//为新加载的页面控件绑定事件
$("#closeBtn").click(function(){
$("#win").window("close");
});
}
});
}
}
$(function(){
windowMain.initWindow();
});
function openWin(){
$("#win").window("open");
}
</script>
<body>
<a href="javascript:void(0);" class="easyui-linkbutton" onClick="javascript:openWin();">打开</a><br><br>
<div id="win"></div>
</body>
</html>
window代码:/EasyUiLearn/WebContent/window/window.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<div class="easyui-panel" style="padding:10px;">
<form id="ff" action="form1_proc.php" method="post" enctype="multipart/form-data">
<table>
<tr>
<td>Name:</td>
<td><input name="name" class="f1 easyui-textbox"></input></td>
</tr>
<tr>
<td>Email:</td>
<td><input name="email" class="f1 easyui-textbox"></input></td>
</tr>
<tr>
<td>Phone:</td>
<td><input name="phone" class="f1 easyui-textbox"></input></td>
</tr>
<tr>
<td>File:</td>
<td><input name="file" class="f1 easyui-filebox"></input></td>
</tr>
<tr>
<td><a id="closeBtn" class="easyui-linkbutton" href="javascript:void(0)">关闭</a></td>
<td></td>
</tr>
</table>
</form>
</div>
要点:
- 页面添加window div。
<div id="win"></div>
- window初始化。
$("#win").window({})
页面就在完成后调用window初始化。windowMain.initWindow();
- window加载完成调用
onLoad
,在这个方法中给window.jsp页面的控件绑定事件。 - 打开window。
$("#win").window("open");
- 关闭window。
$("#win").window("close");
网友评论