我打开了一个新窗口,现在这个新窗口中有一个按钮。在此按钮下有一个 JavaScript 函数,该函数应提交表单并将一些内容插入到 <p>
中。 。此“要添加”的内容还有一个 html 元素(关闭按钮)。
此插入作业无法正常工作。这是我尝试过的:
myWindow.document.write("<scrip" + "t>function closeme(){ document.getElementById('danke').innerHTML='thanks <input type=\'button\' onclick=\'window.close()\'/>'; } </sc" + "ript>");
有人可以帮我吗?
最佳答案
正如评论中所说,有更好的方法来插入脚本,但为了回答问题,您还必须转义转义字符,以便它们出现在输出中。
myWindow.document.write("<scrip" + "t>function closeme(){ " +
"document.getElementById('danke').innerHTML='thanks <input type=\\\'button\\\' " +
"onclick=\\\'window.close()\\\'/>'; } </sc" + "ript>");
(为了便于阅读而添加换行符)
关于javascript - window.document.write - 编写 html 元素等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14380836/