thickbox提交数据后关闭子窗口刷新父窗口

1.父页面添加引用
<script type="text/javascript" src="<web.path:path/>/js/jquery.js"></script>
<script type="text/javascript" src="<web.path:path/>/js/thickbox.js"></script>
<link rel="stylesheet" href="<web.path:path/>/resources/css/thickbox.css" type="text/css" media="screen" />

2.父页面添加如下按钮,引用thickbox打开子窗口
<input alt="<web.path:path/>/bannedUserList!unBannedUserList?height=400&width=800&inlineId=myOnPageContent" title="Ban Another Users" class="thickbox" type="button" value="Ban Another"/>

3.子页面添加按钮或链接
<input id="banUser" type="button" value="Save"/>
<input id="closeBT" type="button" value="Cancel"/>

4.子页面添加相关jQuery和thickbox代码(因为父页面已经引用了jQuery和thickbox库,子页面不需要再引用)
<SCRIPT type="text/javascript">
$("#closeBT").click(function(){
    tb_remove();
});

//click the save button to submit, close the current window and refresh the opener window
$("#banUser").click(function(){

    //get the transfer params
    var users = new Array();
    $("input:checkbox").each(function(){
        if(this.checked) {
            users.push($(this).val());
        }
    });
   
    $.ajax({
        type:"POST",
        url:"<web.path:path/>/bannedUserList!banUser",
        data:"users="+users.join(","),
        success:function(msg){
            tb_remove();    //close the thickbox
            var win = top.window;
            try{
                if(win){
                   win.location.reload();     //refresh the opener window
                }
            }catch(ex){}
        }
    });

});
</SCRIPT>

你可能感兴趣的:(JavaScript,jquery,Ajax,Web,css)