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

Pet*_*ter 3 css jquery

我有一个网站,其中HTML只是一团糟(由SharePoint设计师生成).

我需要打印页面,但它看起来像IE7/8打印预览中的废话,所以我需要 <style type="text/css" media="print">用来改变一些表,div等,但很多元素没有类或ID.有没有办法一起使用打印样式表和jQuery来查找元素?当我在Google上搜索时,大多数链接都是关于切换样式表的.

提前致谢.

Mar*_*rko 5

您可以使用jQuery强大的选择器来实际添加您可能需要的类,然后可以从打印样式表中访问它们.

例如.

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

只是为了好玩,这里有一些jQuery魔法,它会为你的所有表和表中的所有行添加一个类(编号).

$("table").each(function(index, value) {
    $(this).addClass("table" + index);
    $("tr", this).each(function(index, value) {
        $(this).addClass("row" + index);
    });
});
Run Code Online (Sandbox Code Playgroud)

如果您在指定特定元素方面需要帮助,请将它们发布在您的问题中,我们很乐意为您提供帮助.