JS implementation of local selection of print and local do not select print

Source: Internet
Author: User

  This article mainly introduces the choice of JS print content, mainly to print their own things with a div layer to hold up, need friends can refer to the following

Because the project needs to select the printed content in one page.     Pick up what you want to print with a div layer. For example, the:  code is as follows: <!--referral to the office to inform the-->  <div id= "Itemvrbjform" style= "font-family: ' Imitation ', ' Arial '; Font-size: 18px; margin-top:290px, ">  <div style=" width:600px; margin:0 auto; " >  <div style= "float:right;margin-top: -40px;" > (Notification Order number: ${zjxfitemuser.acceptedno}) </div>  <div id= "title" style= "margin-top:40px;" ><span > Petition Matters Forwarding notice </span></div>  ${zjxfitemuser.username}: (Name of the complainant) <br/>            <span id= "Itemvrbjtime" ></span&gt, the Agency (or unit) has accepted your (or your) proposed ${zjxfitemuser.subject} petition matters in accordance with the law ,  the matter under the terms of reference of XXX, according to the relevant provisions of the regulations on letters and visits, the authority has been in XXXX xx month XX days to transfer the relevant materials to XXX processing, please contact with the timely. <br/>            hereby inform. <BR/>  <div style= "margin-top:50px;margin-right:20px;float:right;" > (Cover ${zjxfprocessover.suborgname} special chapter or official seal) </div>  <div style= "margin-top:90px;margin-right: -190px; Float:right; " ≫<span id= "Itemvrbjendtime" ></span></div>  </div>  </div>  <!-- Petition matters transfer to the Office to inform the single end-->    in the middle there is no need to print, but also with a div layer included. Using CSS styles in the. Reference class= "noprint" in layers that do not need to be printed the   code is as follows: <style type= "text/css" media= "print" > . Noprint{visibility: none;}   </style>    JS code:    NOTE: When you choose to print, the style will be lost, you need to print before printing.     Code as follows: $ (function () {    $ ("#print"). Click (function () {    var html = window.document.body.innerhtml;    EXPORTCSS ("Itemvrbjform", html);   });   // Import style to select print   function exportcss (formname,htmlinfo) {  var CSS = "<link href=" "+ BaseURL +"/zjxf/common/css/ Common.css "type=" Text/css "rel=" stylesheet "/>" +  "<link href=" "+ BaseURL +"/zjxf/common/css/table.css " Type= "Text/css" rel= "stylesheet"/> "+ " <link href= "" + BaseURL + "/zjxf/common/css/form.css" type= "text/css "Rel=" stylesheet "/>" +  "<link href="" + BaseURL + "/zjxf/common/css/tab.css" type= "Text/css" rel= "stylesheet"/> "+ " <link href= "" + BaseURL + "/ Zjxf/common/css/print.css "type=" Text/css "rel=" stylesheet "/>";  $ (CSS). Appendto ("#" + formName);  Window.document.body.innerHTML = $ ("#" + formName). HTML ();  window.print ();  Window.document.body.innerHTML = htmlinfo; }   });    This enables both local and local-not-select printing    

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.