Javascript window.document.write-编写html元素等

Javascript window.document.write-编写html元素等,javascript,html,document.write,Javascript,Html,Document.write,我打开了一个新窗口,现在这个新窗口中有一个按钮。在这个按钮下有一个JavaScript函数,它应该提交表单并将一些内容插入。这个“添加”内容还有一个html元素(关闭按钮) 此插入作业不起作用。以下是我尝试过的: myWindow.document.write("<scrip" + "t>function closeme(){ document.getElementById('danke').innerHTML='thanks <input type=\'button\' on

我打开了一个新窗口,现在这个新窗口中有一个按钮。在这个按钮下有一个JavaScript函数,它应该提交表单并将一些内容插入
。这个“添加”内容还有一个html元素(关闭按钮)

此插入作业不起作用。以下是我尝试过的:

myWindow.document.write("<scrip" + "t>function closeme(){ document.getElementById('danke').innerHTML='thanks <input type=\'button\' onclick=\'window.close()\'/>'; } </sc" + "ript>");
myWindow.document.write(“函数closeme(){document.getElementById('danke').innerHTML='谢谢';}”);

有人能帮我吗?

正如评论中所说,插入脚本有更好的方法,但为了回答这个问题,您还必须转义转义字符,以便它们出现在输出中

myWindow.document.write("<scrip" + "t>function closeme(){ " + 
"document.getElementById('danke').innerHTML='thanks <input type=\\\'button\\\' " + 
"onclick=\\\'window.close()\\\'/>'; } </sc" + "ript>");
myWindow.document.write(“函数closeme(){”+
“document.getElementById('danke').innerHTML='Thanke';}”);

(为了便于阅读,增加了换行符)

我同意有更好的方法,但是关于你的具体问题。存在以下问题:

myWindow.document.write("<scrip" + "t>function closeme(){ document.getElementById('danke').innerHTML='thanks <input type=\"button\" onclick=\"window.close()\" />'; } </sc" + "ript>");
myWindow.document.write(“函数closeme(){document.getElementById('danke').innerHTML='谢谢';}”);

为了保持一致性,我会诚实地添加
text/javascript

首先,不要使用
document.write
-而是通过
createElement
创建脚本元素。这将减轻你的报价内的报价内的报价噩梦。其次,没有任何函数调用你的
closeme
函数?@jbabey,没有,我的函数
closeme
正在被调用,我只是没有在这里发布,因为我确信它正在被调用。但一般来说,
createElement
是更好的方法?-:))你让我笑了!如何将jquery链接到文档<代码>myWindow.document.write(“”)
myWindow.document.write(“jquery链接”)
myWindow.document.write(“”)
这样可以吗?