html局部打印


html頁面局部打印的小栗子

只要修改點擊打印的按鈕和打印的div區域的id就行啦

<!DOCTYPE html>
<html>
<head>
  <title>print test page</title>
  <meta charset="utf-8">
  <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js">
</script>
<script type="text/javascript">
//貌似要jq 1.6版本以上才支持prop函數
  $(document).ready(function(){
    var print_click = "print"; //打印的按鈕的id
    $("#" + print_click).bind("click", function(){
      var print_id = "print_content"; //要打印的div的id
      var k = $("#" + print_id).prop("outerHTML");
      $("body *").hide();
      $("body").append(k);
      window.print();
      $("body *").show();
      $("body #" + print_id + ":last").remove()
    })
  })
</script>
</head>
<body>
<div>
  <div>不需要打印</div>
  <div id="print_content">打印的內容</div>
  <button id="print">打印</button>
</div>
</body>
</html>

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM