22

そのため、1 つの要素 (クラス / id / タグ名 / 属性など) に適用されるすべてのスタイルをコピーしようとしています。これまでのところ、要素の計算されたスタイルをコピーできることがわかりました.1つだけ問題があります...それを外側の要素に適用できます;/

または、すべてのスタイルをコピーする方法を変えます。

(これは私が得た限りです:/) http://jsfiddle.net/8KdJd/2/

   //queriks mode + minor changes to retrive the computed style
function getCS(el)
{
    if (el.currentStyle)
        var y = el.currentStyle;
    else if (window.getComputedStyle)
        var y = document.defaultView.getComputedStyle(el,null);
    return y;
}
function setCS(el,cs)
{
    if (el.currentStyle)
    {

        el.currentStyle = cs;
        el.style = cs;
    }
    else if (window.getComputedStyle)
    {el.style = cs 
    }

}


var myLink = document.getElementById('myLink');
var anotherLink = document.getElementById('anotherLink');

var CS_myLink = getCS(myLink);
setCS(anotherLink,CS_myLink);
4

3 に答える 3