我对 jquery 很陌生,我试图用它在我非常简单的网页底部放置一个打印按钮,但我根本无法让它显示。 (我将在页面上打印更多内容,我只是还没有包含它,因为没有必要)这是我到目前为止的代码:
<html>
<head>
<h1>This is my webpage</h1>
</head>
<body>
<div class="col_2">
<script>
<img src="print.png" class="printMe" alt="Print" title="Print"></a>
$('.printMe').click(function(){
window.print();
});
</script>
<img src="gvsu.png">
<a href="https://www.linkedin.com"><img src="linkedin.png" alt="HTML tutorial" width="42" height="42"></a>
<a href="https://www.twitter.com"><img src="twitter.png" alt="HTML tutorial" width="42" height="42"></a>
<a href="https://www.facebook.com"><img src="fb.png" alt="HTML tutorial" width="42" height="42"></a>
</div>
</body>
</html>
最佳答案
我重写了代码并添加了jquery库。这个版本可以正常工作。只需替换为您自己的图像即可。
<html>
<head>
<title>This is your page title</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<div class="col_2">
<h1>This is my webpage</h1>
<img src="print.png" class="printMe" alt="Print" title="Print" />
<img src="gvsu.png" />
<a href="https://www.linkedin.com"><img src="linkedin.png" alt="HTML tutorial" width="42" height="42"></a>
<a href="https://www.twitter.com"><img src="twitter.png" alt="HTML tutorial" width="42" height="42"></a>
<a href="https://www.facebook.com"><img src="fb.png" alt="HTML tutorial" width="42" height="42"></a>
</div>
<script>
$(document).ready(function() {
$('.printMe').click(function(){
window.print();
});
});
</script>
</body>
</html>
关于javascript - JQuery 打印按钮不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24175627/