javascript - JQuery 打印按钮不显示

标签 javascript jquery html

我对 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/

相关文章:

html - 仅将一些变量从 html 表单发送到电子表格

javascript - JQuery 使用什么类型的缩小器?

javascript - 一种通过JS保存HTML结果的方法

javascript - 如何在 HTML 页面上隐藏/显示图像

javascript - 使用 Jquery 从 <tr> 元素获取源代码

php - Chrome 的滚动延迟

javascript - Google Places API 无效值错误 : not an instance of HTMLInputElement

javascript,我的补码没有产生正确的数字

javascript - php和js重定向错误

javascript - 如何将 javascript 变量传递到 JSON 对象上的 Each 循环 (jQuery)