如何使用jQuery打印一个页面
这个任务是当用户点击一个Button时,通过调用window.print方法,用jQuery打印一个页面。window.print()方法是用来打开打印对话框来打印当前文档的。它没有任何参数值。
示例: :
HTML 代码:
<!DOCTYPE html>
<html>
<head>
<title>
How to. print a page using jQuery.?
</title>
</head>
<body>
<center>
<h1>Hello GeeksForGeeks Users</h1>
<h3>
How to. print a page using jQuery.?
</h3>
<Button id="sudo" onclick=
"print_current_page()" />
Print!
</center>
</body>
</html>
jQuery 代码:
$('#sudo).click(function(){
window.print();
return false;
});
输出:
在点击按钮之前:
点击按钮后:
支持的浏览器:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari