javascript - 单击按钮后更改打印样式

标签 javascript jquery css

这个:

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

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

作品类型。我说有点,因为实际的打印样式仅在我第二次单击 ID 为“printStyle2”的按钮后才应用。这种行为的原因可能是什么?旧打印样式的某种缓存?

最佳答案

浏览器确实需要一些时间来应用所有更改。所以:

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

成功了。

关于javascript - 单击按钮后更改打印样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16262249/

相关文章:

jquery - WYMeditor 在空时插入 <br/>

css - 如何强制嵌入链接使用我的 CSS 样式

html - 鼠标悬停在图像上的 css/html 格式文本

javascript - Crocodoc 文档字体在移动设备上太小

javascript - 为什么 jQuery .html(string) 将 type 属性移到输入的末尾?

javascript - 为什么添加商品的方法不正确?

javascript - 如何阻止 <a> 标签跳转到 href 属性指定的目标?

html - 猫头鹰旋转木马 2 中图像之间的空白

javascript - 使用 includes、extends 和 blocks 时,jade 脚本加载顺序似乎很奇怪

javascript - undefined object 方法