【发布时间】:2019-10-02 17:25:04
【问题描述】:
我们在 javascript 中使用document.write() 在 HTML 文档中写入任何内容。这可以在 Jquery 的帮助下通过单击新选项卡中的按钮来完成吗?
var newHTML = "<html><head></head><body><div class='test-class'><p>this is a test div for the next page print with external appended jquery script.</p><h1>this is heading for extra content in page</h1></div></body></html>";
$(document.body).append(newHTML);
这不起作用。我想要那个,点击按钮 newHTML's content open in new tab
【问题讨论】:
-
你应该避免 document.write。它有一些用途,但大多数情况下它是不适合这项工作的工具。这有点像用锤子打开窗户。它可以工作,但有更好的方法可以打开一个窗口。
-
您从 document.write 中看到了哪些无法从 jQuery 追加获得的功能?
标签: javascript jquery