如何添加一个CSS文件到页面的主体? [英] how can i add a css file to body of a page?
本文介绍了如何添加一个CSS文件到页面的主体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在处理一个具有打印视图的页面,因此当用户单击打印时,弹出一个新窗口,并且我想为该窗口添加一个.css文件。
I am working on a page which has a print view so when the user clicks on "Print" a new window pops up and I want to add a .css file just for that window.
感谢
推荐答案
$(document).ready(function () {
$(".print").click(function () {
$("head").append("<link>");
css = $("head").children(":last");
css.attr({
rel: "stylesheet",
type: "text/css",
href: "css/ecsPrint.css"
});
return false;
});
});
除非这是内部Web应用程序,否则我不建议用JS加载css。
Unless this is a Internal Web Application, i wouldnt recommend loading css with JS.
这篇关于如何添加一个CSS文件到页面的主体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文