Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery-新窗口中的元素未定义_Javascript_Jquery_Html - Fatal编程技术网

Javascript jQuery-新窗口中的元素未定义

Javascript jQuery-新窗口中的元素未定义,javascript,jquery,html,Javascript,Jquery,Html,我有一段代码,试图创建一个新窗口,然后向用户提示id=“chatbody”元素中的html 下面是window.HTML的HTML <!DOCTYPE HTML > <html lang = "en"> <head> <link rel="stylesheet" href="main_style.css"> <script src="http://layout.jquery-dev.net/lib/js/jquery-late

我有一段代码,试图创建一个新窗口,然后向用户提示id=“chatbody”元素中的html

下面是window.HTML的HTML

<!DOCTYPE HTML >
<html lang = "en">
<head>
    <link rel="stylesheet" href="main_style.css">
    <script src="http://layout.jquery-dev.net/lib/js/jquery-latest.js"></script>
    <script src="windowScript.js?n=10"></script>
</head>
<body>
 <table id = "chatboxFull">
    <tr><td id="chatbody">
        derp!
    </td></tr>
</table>

<br>
<p1>&nbsp;<input id="msg" type="text" />    &nbsp; 
<input id="send_msg" type="button" value="Send" /> </p1>
</body>
</html>

德普!

我遇到的问题是,框提示“未定义”,而不是预期的“derp!”。如果相关的话,我正在使用谷歌浏览器。有人知道为什么会这样吗?

试试这个:

var w = window.open("window.html", "Messaging with " + $(this).text(), "height=250,width=400");
$(w).load(function()
{
    alert($("#chatbody", w.document).html());
});

如果需要它提醒子窗口的#chatbody html的主窗口,请使用
alert($(“#chatbody”,w.document).html())


请参阅第二个参数。

不要将函数的开头括号放在新行上。呵呵。那很有趣。但它不能解决我的问题。据我所知,如果没有w,它将不会查看孩子的ID。对不起,我误解了你的问题。我已经编辑了我的答案。看看这对你是否有效。我试过这个,但很遗憾,它也会导致同样的问题。我认为,这只是缩小了对chatbody元素的搜索范围,这可能与如何在window.html中呈现chatbody的内容有关。它只是静态文本还是通过Javascript添加的?如果你查看html文件,它应该只是静态文本。那么没有任何线索。如果您仍然被卡住,测试台可能会有所帮助,这样我们就可以打开一个包含实际页面的新窗口。
var w = window.open("window.html", "Messaging with " + $(this).text(), "height=250,width=400");
$(w).load(function()
{
    alert($("#chatbody", w.document).html());
});