使用JQuery将内容写入新窗口 [英] Write Content To New Window with JQuery
本文介绍了使用JQuery将内容写入新窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有DIV元素的网页.当用户单击打印"时,我要打印该div的内容.请注意,我只想打印DIV的内容,而不是整个页面.为此,我决定使用JavaScript打开一个新窗口.然后,我打算将DIV的内容写入新窗口.我的问题是,使用JQuery是否可能?如果是这样,怎么办?目前,我正在尝试以下操作:
I have a web page with a DIV element in it. When a user clicks "print", I want to print the contents of that div. Please note, I only want to print the contents of the DIV, not the entire page. To attempt this, I decided I would open a new window using JavaScript. I was then going to write the contents of the DIV into the new window. My question is, is this possible with JQuery? If so, how? Currently, I'm trying the following:
function printClick() {
var w = window.open();
var html = $("#divToPrintID").html();
// how do I write the html to the new window with JQuery?
}
推荐答案
您可以使用
$(w.document.body).html(html);
请参见此示例
这篇关于使用JQuery将内容写入新窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文