function printDiv(divId) {
//Get the HTML of div
var divElements = document.getElementById(divID).innerHTML;
var oldPage = document.body.innerHTML;
//Reset the page's HTML with div's HTML only
document.body.innerHTML =
"<html><head><title></title></head><body>" +
divElements + "</body>";
//Print Page
window.print();
//Restore orignal HTML
document.body.innerHTML = oldPage;
}
第一个标签的div内容是使用上述功能打印的,但我有多个标签,只需点击一下即可打印出来。