java 打开一个窗口

功能简介:登录后进入index页面,index有导航页签,点击某个导航页签进入某个功能页面main.jsp,mian.jsp的页面上有“添加”或者“编辑”的按钮,点击这些按钮弹出一个jsp的页面,方法如下:

index.jsp的js方法:

var windowopen = null; // 如果main页面有datagrid需要在新增或编辑后进行刷新,则定义一个全部变量

function showIframeDialog(title, width, height, url) {
var $iframe = $("<iframe />").css({
width: width,
height: height,
border: "none"
}).attr("frameborder", false);
var $container = $("<div/>").append($iframe).appendTo($(document.body));
$container.dialog({
title: title,
modal: true,
});
$iframe.attr("src", url);
}

function closeIframeDialog(iframeElement) {
$(iframeElement).parent().dialog("close");
}

 

main.jsp页面调用:

function add(){
window.top.windowopen = this;
window.top.showIframeDialog(
"添加",
window.screen.width * 0.6,
window.screen.height * 0.45,
"LawManage/OfficersManage/OfficersManage-add.jsp");

}
function redatagrid(){
$("#dg").datagrid("reload");
}

function edit(){
var dataSelected = $('#dg').datagrid('getSelected');

if(dataSelected == null){
$.messager.alert('提示','请选择一条记录!','info');
}
else{
window.top.windowopen = this;
var row = $('#dg').datagrid('getSelected');
window.top.showIframeDialog(
"编辑",
window.screen.width * 0.6,
window.screen.height * 0.4,
"LawManage/OfficersManage/OfficersManage-edit.jsp?userid="+row.userid);

$('#dg').datagrid('load', {
gridid:$('#gridid').combobox('getValue')
});

}

}

 

新增的jsp页面的js中这样使用:

var formData = {
// userid : $('#add_loginname').val(),
loginname : $('#add_loginname').val(),
realname : $('#add_realname').val(),
responsiblegrid : $('#add_responsiblegrid').combobox('getValue'),
sex : $('#sex input[name="add_sex"]:checked ').val(),
password : $('#add_password').val(),
repassword : $('#add_repassword').val(),
phone : $('#add_phone').val(),
position : $('#add_position').combobox('getValue'),
address : $('#add_address').val(),
active : $('#add_active').val()
};
$.ajax({
url : getContextPath() + "/officersmanage/getCheckLoginname.do",
data : {loginname : $('#add_loginname').val()},
type:"post",
traditionnal : true,
success : function(data){
if(data == "success"){
var checkloginname=document.getElementById ("checkloginname");
checkloginname.innerHTML = "用户名已存在!";
$('#add_loginname').val("");
}else{
$.ajax({
url : getContextPath() + "/officersmanage/saveOfficersInfo.do",
data : formData,
type : "post",
// dataType : "json",
traditional : true,
success : function(returndata) {
if (returndata == "success") {
$.messager.alert("提示", "保存成功!", 'info', function() {
window.top.windowopen.redatagrid();  //刷新main页面的datagrid
window.top.closeIframeDialog(window.frameElement);  //关闭新增页面
});
} else {
$.messager.alert('提示', '保存失败:' + returndata.message + '!',
'error');
}
}
});
}
}

});

 

posted @ 2016-04-26 14:22  安静的程序媛  阅读(932)  评论(0编辑  收藏  举报