js调用浏览器打印

时间:2020-12-19 21:30:58

<input type="button" id="print" onclick="printdiv('list');" value="打印"/>
<script type="text/javascript">
function printdiv(list) {
$("#print_value").val("打印");
$("#info .or").addClass("operation");
$("#container").addClass("container");

//先获取内容
var printData = $("#list").html();

//

var oldstr = document.body.innerHTML;

//
document.body.innerHTML = printData;

//调用浏览器打印

window.print();

//
document.body.innerHTML = oldstr;
return false;
}
</script>