如何使用jQuery删除继承的样式?

如何使用jQuery删除继承的样式?,jquery,css,Jquery,Css,大家好,我有一个DIV,我通过了一个js函数: function print(divId) { var det = document.getElementById(divId); $(divId).removeClass(); .. $(divId).removeAttr(); .. var mywindow = window.open(' ', 'Print'); mywindow.docu

大家好,我有一个DIV,我通过了一个js函数:

function print(divId) {
        var det = document.getElementById(divId);

        $(divId).removeClass();  ..
        $(divId).removeAttr();   ..        

       var mywindow = window.open(' ', 'Print');
        mywindow.document.write('<html><head><title>Account Detail</title>');
        mywindow.document.write('<link href="../../css/reset-min.css" rel="stylesheet" type="text/css" />');
        mywindow.document.write('</head><body>');
        mywindow.document.write(det.innerHTML);
        mywindow.document.write('</body></html>');
        } 
函数打印(divId){
var det=document.getElementById(divId);
$(divId).removeClass()。。
$(divId).removeAttr()。。
var mywindow=window.open(“”,'Print');
mywindow.document.write('Account Detail');
mywindow.document.write(“”);
mywindow.document.write(“”);
mywindow.document.write(det.innerHTML);
mywindow.document.write(“”);
} 
我已经尝试过一些jQuery函数,如上面所示,buy it not works,因为样式是从css模板继承而来的,所以我如何才能完全删除css和styles属性。。我听说YUI重置,但我不知道如何在新的Windows弹出窗口中使用它


谢谢

创建一个覆盖所有继承属性的CSS类,然后从div中删除所有类并添加覆盖所有内容的CSS类。

只需使用
.CSS(
并记住附加!必要时强制覆盖非常重要


这将有效地设置元素上的
style=“
属性。

我认为您需要克隆目标节点以删除其中每个元素的属性:

var det = document.getElementById(divId);
if (det) {
    det = det.cloneNode();
    $(det).removeAttr("class").removeAttr("style").find("*").each(function(i, elem) {
        $(elem).removeAttr("class").removeAttr("style");
    });

    // …
}
这些措施是否有助于:

$("link[rel=stylesheet][class=must-remove-when-printing]").remove();
以及:


jquery不会解决它,但浏览器会解决。你并没有真正“清除”"如果你应用了一个全局div属性,例如,没有办法让jquery隐藏该属性,你只能用另一个类覆盖它。jquery可能会影响像divId这样的动态参数,考虑到它是一个div html对象,我只想应用那些对Styles在此元素中。@AngelesCabedo什么?你的评论毫无意义。按照我说的做就足以满足你的要求。你对这个评论说什么?因为我使用的函数带有一个包含整个div的参数,所以我想知道jQuery选择器是否可以对此作业修改css选择器正在返回div。div包含子项。jQuery选择器用于div。jQuery选择器不用于子项。你不知道这是如何工作的,是吗?我没有使用$(document)。ready()触发单击打印按钮,我可以这样做吗?我有一个用于重置Css和样式的Css类,但不知道如何使用.Attr调用,我尝试过:$(divId).attr('class','reset-min.css');是否将css文件附加到弹出窗口中加载的文档?
$("*[class]").removeAttr("class");
$("*[style]").removeAttr("style");