我编写了以下脚本来打印页面。
是否可以在以下标记之后不打印HTML
<font class="productnamecolorSMALL colors_productname"><b>Related Items</b></font>
含义忽略上述
后的打印<p>Click the button to print the current page.</p>
<button onclick="myFunction()">Print this page</button>
<script>
function myFunction() {
window.print();
}
</script>
答案 0 :(得分:1)
Alexis Wilke建议添加打印样式表。
此css将使用相邻的同级选择器从打印页面中删除.productnamecolorSMALL的第一个相邻兄弟。您可以使用任何css来标记要删除的内容或在打印时以不同方式显示。所以只需根据需要编辑打印样式表。
HTML
<?php
include ('php/data/sitename.php');
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $sitename; ?> - Home</title>
<!--Import Google Icon Font-->
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/>
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<div class="container">
<!-- HEADER: Navbar -->
<?php $navbar; ?>
<!-- MAIN: Index Page contents -->
<?php $page_index ?>
<!-- FOOTER: Footer -->
<?php $footer; ?>
<?php $sitename; ?>
</div>
<!--Import jQuery before materialize.js-->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="js/materialize.min.js"></script>
</body>
</html>
<强> CSS 强>
<?php
include ('../db.php');
$sql = "SELECT id, sitename FROM GeneralData";
$getname = mysqli_query($conn, $sql);
if ($getname->num_rows > 0) {
while($row = $getname->fetch_assoc()) {
$sitename = $row['sitename'];
echo $sitename;
}
}
?>