下面这段是我的页面代码,我想用CSS样式控制打印的部分,但是不管我怎么写
,打印预览的时候输出的数据都不能显示,看不到,只能看到客房状态查看 还有第几页几个字 关键的数据部分都显示不了 是怎么回事
<?php session_start();$page=intval($_GET['page']);/*intval()返回变量的intger数值,获取变量的整数值*/ if ($page=="") {$page=1;}?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>客房状态查询</title>
<link rel="stylesheet" type="text/css" href="style.css">
<style type="text/css">
<!--
.STYLE1 {color: #FFFFFF}
.STYLE2 {font-size: 12px}
.STYLE4 {font-size: 13px}
.STYLE5 {font-family: "华文琥珀"; font-size: 20px;}
-->
@media print{
div{display:none}
.bgnoprint{
    background:display:none;
}
.noprint{
    display:none
}
}
body {
    margin-top: 0px;
}
</style>
</head>
<body bgcolor="#7791EA" class="bgnoprint">
<object id="WebBrowser" classid="ClSID:8856F961-340A-11D0-A96B-00C04Fd705A2" width="0" height="0">
</object>
<table width="500" height="60" border="0" align="center" cellpadding="0" cellspacing="0">
     <tr>
    <td align="center" class="STYLE5">客房状态查看</td>
  </tr>
</table>
<table width="500" height="10" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td></td>
  </tr>
</table>
<table width="500" height="50" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td bgcolor="#256B25" valign="middle">
    <table width="500" height="50" border="0" align="center" cellpadding="0" cellspacing="1">
      <tr>
        <td width="100" height="25" bgcolor="#9ABADA"><div align="center" class="STYLE1">客房号码</div></td>
        <td width="120" bgcolor="#9ABADA"><div align="center" class="STYLE1">客房类型</div></td>
        <td width="100" bgcolor="#9ABADA"><div align="center" class="STYLE1">客房状态</div></td>
        <td width="90" bgcolor="#9ABADA"><div align="center" class="STYLE1">容纳人数</div></td>
      </tr>
    </thead>
      <?php
      include('include/dbconnect.php');
      if($page){
      $page_size=10;                    //每页显示的记录条数
      $query="select count(*) as total from roomlist where roomnum";  //从数据库中读取数据
      $result=mysql_query($query);
      $message_count=mysql_result($result,0,"total");  //获取总的记录数
      $page_count=ceil($message_count/$page_size);     //获取总的页数
      $offset=($page-1)*$page_size;
      $sql=mysql_query("select * from roomlist order by roomnum limit $offset, $page_size");
      $rs=mysql_fetch_array($sql);
      if($rs==false)
       {
      ?>
      <tr>
        <td height="25" colspan="5" bgcolor="#FFFFFF"><div align="center">没有查找到任何记录!</div></td>
      </tr>
    <?php
      }
      else
      { 
       do{
    ?>
      <tr><!--显示查询结果-->
        <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $rs[roomnum];?></div></td>        <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $rs[style];?></div></td>
        <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $rs[condition];?></div></td>
        <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $rs[capacities];?></div></td>  
      </tr>
     <?php
       }while($rs=mysql_fetch_array($sql));
      }
    }
     ?>
     </table> 
  </td>
  </tr>
</table>
<table width="500" border="1" cellpadding="0" cellspacing="0" bgcolor="#9ABADA" align="center">
  <tr> 
   <td width="45%" align="center"><span class="STYLE1">&nbsp;&nbsp;页次:<?php echo $page;?>
      / <?php echo $page_count;?> 页 记录:<?php echo $message_count;?> 条&nbsp; </span></td>
   <td width="55%" height="22" align="center"><span class="STYLE1"> 分页: 
      <?php
                  if($page!=1)
                   {
                     echo  "<a href=main_index.php?lm=客房状态查看>首页</a>&nbsp;";
                     echo "<a href=main_index.php?lm=客房状态查看&page=".($page-1).">上一页</a>&nbsp;";
                   }
                  if($page<$page_count)
                   {
                        echo "<a href=main_index.php?lm=客房状态查看&page=".($page+1).">下一页</a>&nbsp;";
                        echo  "<a href=main_index.php?lm=客房状态查看&page=".$page_count.">尾页</a>";
                   }
      ?>      
    </span></td>
  </tr>
</table>
<table width="500" align="center">
            <tr align="center">
              <td width="500" height="27" colspan="3" align="right" class="noprint"><span class="style1"><a href="#" onClick="document.all.WebBrowser.Execwb(7,1)">打印预览</a> <a href="#" onClick="document.all.WebBrowser.Execwb(6,1)">打印</a> <a href="#" onClick="document.all.WebBrowser.Execwb(6,6)">直接打印</a> <a href="#" onClick="document.all.WebBrowser.Execwb(8,1)">页面设置&nbsp;</a></span> </td>
            </tr>
          </table>
<table height="80">
    <tr><td></td></tr>
</table>
</body>
</html>

解决方案 »

  1.   

    去掉@media print{
    div{display:none}
    .bgnoprint{
        background:display:none;
    }
    .noprint{
        display:none
    }
    }
    这段  也就是CSS控制打印的这段 可以打印预览,但是就把所有的东西都打印出来了
      

  2.   

    在media print中写的隐藏样式 也就是打印出来的时候不显示 打印预览效果也一样 
      

  3.   

    @media print{
    .noprint{
        display:none
    }
    }
    在需要隐藏的地方加class="noprint"就可以了。