JavaScript如何复制控件的样式啊? 如题·我需要将A控件的样式复制给B控件(A控件的样式不定!)请问该如何实现? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 个人觉得可以使用jquery jquery 可以动态的得到样式和添加样式 样式无非就是style和class,当然还有些是继承上级 不过这样也不一定相同因为css有选择器 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]; }} for (key in target.style)在每次Key='clip'的时候,都会报参数无效··· 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; } } }} 有些特殊属性需要特别处理,如IE下的filter,LZ自行处理以上代码已在ie/ff/op/sa/ch下测试过了 谁帮忙看下这个JS文件那里误,在IETester下测试报错 急急·正则表达式求助 如何用js控制生成表格列的宽度 jquery .html方法与struts标签库的使用问题 求一个将每段开头和结尾的所有空格去掉的正则函数 关于js的规范验证问题 高手帮忙有偿修改一个网页 这个问题如何解决呢? 如何动态控制marquee标记的滚动速度? 如下代码为何显示不出来? 关于任务栏asp托盘图标的问题! JS如何实现这种右下角弹出效果并且滚动页面时无刷新?
因为css有选择器
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];
}
}
for (key in target.style)
在每次Key='clip'的时候,都会报参数无效···
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;
}
}
}
}
以上代码已在ie/ff/op/sa/ch下测试过了