简体   繁体   中英

Two print buttons with different css on the same page… Possible?

I'm working with Dreamweaver, coded in php .

On one of my pages, I'm trying to add 2 different print buttons , each one printing a differrent portion of the webpage. For example, one print button is printing the first paragraph and the other print button is printing the second paragraph .

I did the print CSS for both buttons and I linked each to its respective print CSS , but the second print CSS overrules the first one, and so I end up having two print buttons with the same CSS...

What do I need to do?

You could dynamically change the print CSS based upon which button is clicked with something like this:

Add an id to your stylesheet reference:

<link rel="stylesheet" href="print1.css" id="printCss" media="print">

Add an on click event to your button:

<input type="button" onclick="swapCss();"/>

Dynamically swap the css file:

function swapCss() {
    document.getElementById('printCss').href = 'print2.css';
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM