相关疑难解决方法(0)

将javascript计算样式从一个元素设置为另一个元素

所以我试图复制适用于一个元素的所有样式(class/id/tagName/attribute等).到目前为止,我发现我可以复制元素的计算样式,只有一个问题... couldend将它应用于其他元素; /

或diffrend复制所有样式的方法.

(这是我得到的:/) 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);
Run Code Online (Sandbox Code Playgroud)

javascript clone copy set computed-style

11
推荐指数
2
解决办法
9541
查看次数

标签 统计

clone ×1

computed-style ×1

copy ×1

javascript ×1

set ×1