Javascript 在父窗口中单击href时,清除弹出窗口并写入新内容 $.ajax({ 类型:'POST', url:'function.php', 成功:功能(数据){ win=窗口。打开(“,”窗口“,”宽度=620,高度=320,滚动条=yes,标题栏=no,可调整大小=no”); 如果(赢&赢!结束) { win.document.clear(); win.document.writeln(数据); win.document.writeln(“”); win.focus(); } } });

Javascript 在父窗口中单击href时,清除弹出窗口并写入新内容 $.ajax({ 类型:'POST', url:'function.php', 成功:功能(数据){ win=窗口。打开(“,”窗口“,”宽度=620,高度=320,滚动条=yes,标题栏=no,可调整大小=no”); 如果(赢&赢!结束) { win.document.clear(); win.document.writeln(数据); win.document.writeln(“”); win.focus(); } } });,javascript,php,jquery,html,Javascript,Php,Jquery,Html,function.php返回一个html表 在父窗体中包含多个链接,每次按下链接时,我需要根据链接id使用新值刷新内容。您可以使用jQuery删除html和body标记的内容: $.ajax({ type:'POST', url: 'function.php', success: function(data){ win = window.open("", "Window", "width=620,height=320,scrollbars=yes,titl

function.php
返回一个html表


在父窗体中包含多个链接,每次按下链接时,我需要根据链接id使用新值刷新内容。

您可以使用jQuery删除html和body标记的内容:

$.ajax({
    type:'POST',
    url: 'function.php',
    success: function(data){
        win = window.open("", "Window", "width=620,height=320,scrollbars=yes,titlebar=no,resizable=no"); 
        if(win && !win.closed)
        {
            win.document.clear();
            win.document.writeln(data);
            win.document.writeln("<a href='javascript:self.close()'>close window</a>");
            win.focus();
        }  
    }
});

这意味着,function.php必须通过AJAX返回一个完整的页面,或者至少返回页面的主体——作为新内容插入
win.document.writeln(数据)
(如您所拥有)或
$(“body”).html(数据)

这里有一个JSBin可以解决您的问题:(仅在Google Chrome上测试)

您的弹出窗口未被清除,因为您正在对窗口对象调用
getElementsByTagName
。相反,您需要在
窗口.document
对象上调用它。另外,不要将html标记的
innerHTML
设置为空白。如果执行此操作,所有后续的
writeln
调用都将无法工作

另外,请使用
var
声明变量,否则所有变量都将转储到全局范围

$('body').empty();

$('html').empty();