2010-11-19 57 views

回答

2

我想知道,你想要做什麼字符串border: 1px solid #000

說要複製一個elems的bordercopyStyle(el2, el, "border")複製:

// Copies a set of styles from one element to another. 
function copyStyle(dest, source, shorthand) { 
    var computed = window.getComputedStyle(source, null); 
    for (var i = computed.length; i--;) { 
    var property = camelize(computed[i]); 
    if (property.indexOf(shorthand) > -1) { 
     console.log(property) 
     dest.style[property] = computed[property]; 
    } 
    } 
} 

// prototype.js 
function camelize(text) { 
    return text.replace(/-+(.)?/g, function (match, chr) { 
    return chr ? chr.toUpperCase() : ''; 
    }); 
} 

比較如果兩個元素的給定的風格相匹配時,以同樣的方式來完成。除此之外,我真的不能看到使用字符串,如果你想用它來計算任何東西,應該解析它。