网页打印按钮不工作
Webpage Print button not working
我是jQuery和html的新手,我正在尝试在我的网页上制作一个打印按钮。我得到了一个小的打印图像,但点击图像什么也没做。当我的鼠标停留在图像上时,我的光标甚至不会改变。我有一个jQuery函数,用来处理打印的逻辑。有人能看出我做错了什么吗?
这是我目前为止的代码:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet" href="PoliticsHTML_CSS.css" type="text/css"/>
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.5.0/pure-min.css">
<title>Display HTML Table</title>
<script>
$('.printMe').click(function(){
window.print();
});
</script>
</head>
<body>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$con=mysqli_connect("******","*****","***", "***");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "SELECT * FROM PoliticsPoll";
$result = mysqli_query($con, $sql);
echo "<table border='1' class='pure-table-bordered'>
<tr>
<th>ID</th>
<th>Politics Poll Question 1</th>
<th>Politics Poll Question 2</th>
<th>Politics Poll Question 3</th>
<th>Politics Poll Question 4</th>
<th>Politics Poll Question 5</th>
<th>Politics Poll Question 6</th>
<th>Politics Poll Question 7</th>
<th>Politics Poll Question 8</th>
<th>Politics Poll Question 9</th>
<th>Politics Poll Question 10</th>
</tr>";
echo "</table>";
mysqli_close($con);
?>
<img src="print.png" class="printMe" alt="Print" title="Print"></a>
</body>
</html>
您将"click"处理程序添加到一个dom元素,该dom元素(现在)不存在。将<script>
移到<img>
之后,</body>
之前
你不需要使用Jquery,试着把你的打印按钮改成这样:
<script>
function Print () {
window.print()
}
</script>
<img src="print.png" class="printMe" onClick="Print()" alt="Print" title="Print"></a>
很可能是因为printMe元素还不存在,您需要等待它加载完成:
$(document).ready(function() {
$('.printMe').click(function(){
window.print();
});
});
告诉它等待,直到文档加载完成绑定事件处理程序。
相关文章:
- 扩展移相器按钮类不工作
- PHP Javascript显示/隐藏按钮不工作
- Facebook登录按钮没有'不能在Firefox上工作
- 为什么不是'这个jQuery汉堡包按钮不工作
- 隐藏uib弹出按钮点击不工作
- Spring WebFlow2 Javascript只在第一个单选按钮上工作
- 带有向下钻取的 Amchart 图表工作正常,但“后退”按钮不起作用
- 按钮不'我不工作;我又回到了起始页
- 主干点击事件按钮不工作
- 为什么不't在iOS上启动按钮下拉工作
- 类似按钮增量计数器不工作.PHP,AJAX,MySQL,javascript
- Hammer.js滑动不会'单击按钮后才能工作
- Sencha Touch使一个简单的按钮工作
- 提交按钮只能在onchange调用输入文本后第二次点击时工作
- JavaScript 按钮不起作用;代码与其他工作按钮相同
- 如何获得内置进度条的工作按钮动画
- Syncfusion grid with angular support:向rowTemplate中添加工作按钮
- Ng-disabled不工作按钮
- 让Select2 Gem与ActiveAdmin一起工作按钮
- 点击isn't工作按钮