如题·
我需要将A控件的样式复制给B控件(A控件的样式不定!)
请问该如何实现?

解决方案 »

  1.   

    个人觉得可以使用jquery   jquery 可以动态的得到样式和添加样式
      

  2.   

    样式无非就是style和class,当然还有些是继承上级
      

  3.   

    不过这样也不一定相同
    因为css有选择器
      

  4.   

    function getStyle(elem){
    return elem.currentStyle || document.defaultView.getComputedStyle(elem, null);
    }function copyStyle(target, source){
    var key, style = getStyle(source);
    for (key in target.style) {
    target.style[key] = style[key];
    }
    }
      

  5.   


    for (key in target.style)
    在每次Key='clip'的时候,都会报参数无效···
      

  6.   

    function getStyle(elem){
    return elem.currentStyle || document.defaultView.getComputedStyle(elem, null);
    }function copyStyle(target, source){
    var key, style = getStyle(source);
    if (style && style.cssText) {
    target.style.cssText = style.cssText;
    } else {
    for (key in target.style) {
    try {
    if (key != 'length' && key != 'cssText' &&style[key]) target.style[key] = style[key];
    } catch (e) {
    continue;
    }
    }
    }
    }
      

  7.   

    有些特殊属性需要特别处理,如IE下的filter,LZ自行处理
    以上代码已在ie/ff/op/sa/ch下测试过了