简体   繁体   English

<style type =“text / css”media =“print”>和jQuery?

[英]<style type=“text/css” media=“print”> and jQuery?

I have a site where the HTML is just a mess (generated by SharePoint designer). 我有一个网站,其中HTML只是一团糟(由SharePoint设计师生成)。

I need to print the the page, but it looks like crap in IE7/8 print preview, so I need to use <style type="text/css" media="print"> to alter some tables, divs etc, but a lot of the elements have no class or ID. 我需要打印页面,但它看起来像IE7 / 8打印预览中的废话,所以我需要使用<style type="text/css" media="print">来改变一些表格,div等,但是很多元素没有类或ID。 Is there a way to use the print stylesheet and jQuery together to find elements? 有没有办法一起使用打印样式表和jQuery来查找元素? When I search on Google, most of the links are about switching stylesheets. 当我在Google上搜索时,大多数链接都是关于切换样式表的。

Thanks in advance. 提前致谢。

You could use jQuery's powerful selectors to actually ADD classes that you might need, which will then be accessible from your print stylesheet. 你可以使用jQuery强大的选择器来实际添加你可能需要的类,然后可以从你的打印样式表中访问它们。

For example. 例如。

$("p:last-child").addClass("last-para");
$("tr:odd").addClass("odd-row");
$("table:eq(5)").addClass("table6"); // 6th table, starting from a 0 index!

Just for fun, here's some jQuery magic that will add a class (numbered) to all your tables AND all your rows within a table. 只是为了好玩,这里有一些jQuery魔法,它会为你的所有表和表中的所有行添加一个类(编号)。

$("table").each(function(index, value) {
    $(this).addClass("table" + index);
    $("tr", this).each(function(index, value) {
        $(this).addClass("row" + index);
    });
});

If you need help with specifying particular elements, post them in your question and we'd be happy to help. 如果您在指定特定元素方面需要帮助,请将它们发布在您的问题中,我们很乐意为您提供帮助。

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

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