gpt4 book ai didi

javascript - 点击打印页面后,CSS 与实际页面不同

转载 作者:行者123 更新时间:2023-11-28 05:13:04 24 4
gpt4 key购买 nike

这是我要打印的代码:

<div id="printthis">
<?php if(isset($_POST['p_id'])){
$p_id=trim($_POST['p_id']);
$select="select * from `bed_allotment` WHERE `p_id`='$p_id'";
$q=mysqli_query($mysqli,$select);
$bedCount = mysqli_num_rows($q);
if ($bedCount <= 0) {
echo "No Data Found";
return;
}
$row1=mysqli_fetch_assoc($q);
$checkin_date=$row1['checkin_date'];
$tmpDTVar = DateTime::createFromFormat('Y-m-d H:i:s', $checkin_date);
$tmpDTVar = $tmpDTVar->format('Y-m-d');
$checkout_date=date('Y-m-d');
$dateVar1 = DateTime::createFromFormat('Y-m-d', $tmpDTVar);
$dateVar2 = DateTime::createFromFormat('Y-m-d', $checkout_date);
$interval = $dateVar1->diff($dateVar2);
$totalAmt = 0;
$sql = "select bed_allotment.room_id,bed_allotment.bed_id,bed_allotment.checkin_date,bed_allotment.p_id,room_info.room_id,room_info.rate_per_day, room_info.room_type FROM bed_allotment
INNER JOIN room_info ON room_info.room_id=bed_allotment.room_id Where `bed_allotment`.p_id='$p_id' order by checkin_date asc";
$stmt = $conn->prepare($sql);
$stmt->execute();
$ctr=$stmt->rowCount();
if ($ctr > 0) {
$roomid_arr= array();
$roomid_name_arr= array();
$bedid_arr= array();
$dates_arr= array();
$days_arr = array();
$times_arr = array();
$RoomRatesID = array();
$RoomRatesRate = array();
while($row= $stmt->fetch()) {
array_push($roomid_arr,$row['room_id']);
array_push($roomid_name_arr,$row['room_type']);
array_push($bedid_arr,$row['bed_id']);
array_push($dates_arr,$row['checkin_date']);
}
$stmt = $conn->prepare($sql);
$stmt->execute();
while($row = $stmt->fetch()) {
for ($i = 1; $i <= count($dates_arr); $i++) {
$tmpfrom = DateTime::createFromFormat('Y-m-d H:i:s',$dates_arr[$i - 1]);
//var_dump($tmpfrom) ;
if($i == count($dates_arr))
$tmpTo = DateTime::createFromFormat('Y-m-d H:i:s',date('Y-m-d H:i:s'));
else
$tmpTo = DateTime::createFromFormat('Y-m-d H:i:s',$dates_arr[$i]);
$tmpDT = $tmpfrom->diff($tmpTo);
array_push($days_arr, $tmpDT->days);
array_push($times_arr, $tmpDT->h);
}
if (count($roomid_arr) <= 0) {
echo "No Data";
return;
}
if (in_array($row['room_id'],$roomid_arr)) {
array_push($RoomRatesID, $row['room_id']);
array_push($RoomRatesRate, $row['rate_per_day']);
}
}
if($bedCount <= 0) {
echo '
<div id="tow" style="display: none;">';
} else {
echo '
<div id="tow" style="display: block;">';
}
?></div>

这是函数:

<script type="text/javascript">
function printDiv(divName) {
var divToPrint = document.getElementById(divName);
var popupWin = window.open('', '_blank', 'width=1024,height=700');
popupWin.document.open();
popupWin.document.write('<html><link rel="stylesheet" href="css/print.css" type="text/css"><link rel="stylesheet" href="css/style.css" type="text/css"><body onload="window.print()">' + divToPrint.innerHTML +' </html>');
popupWin.document.close();
window.close();
}
function showDiv() {
document.getElementById('tow').style.display = "block";
}
</script>

我只在 print.css 中使用了 display:none,其余的 css 来自 main style.css。我应该怎么办??请帮我。我哪里出错了。

最佳答案

如果您希望您的 css 影响页面的打印版本,您需要添加 media="print":

<link rel="stylesheet" href="css/print.css" type="text/css" media="print">

你试过吗?

关于javascript - 点击打印页面后,CSS 与实际页面不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39446909/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com