简体   繁体   English

单击按钮后更改打印样式

[英]change print style after button click

This: 这个:

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

$('#printStyle2').click(function () {
    $("#printstyle").attr('href', _printStyle2);
    window.print();
    return false;
});

kind of works. 种作品。 I say kind of, as the actual print style is only applied after I click the button with the id 'printStyle2' a second time. 我说的是这样,因为实际的打印样式仅在第二次单击ID为'printStyle2'的按钮后才应用。 What could be the reason for this behavior? 发生这种现象的原因可能是什么? Some kind of caching of the old print style? 某种旧打印样式的缓存?

The browser needs indeed some time to apply all the changes. 浏览器确实需要一些时间才能应用所有更改。 So: 所以:

window.setTimeout(function() { window.print(); }, 1000);

does the trick. 绝招。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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