您好,欢迎访问一九零五行业门户网

JS.elementGetStyle(element, style)应用示例_javascript技巧

注: 获取dom元素的style数组中的指定style元素
复制代码 代码如下:
function elementgetstyle(element, style) {
var value = null;
if (element.style) {
value = element.style[style];
}
if (!value) {
if (document.defaultview && document.defaultview.getcomputedstyle) {
var css = document.defaultview.getcomputedstyle(element, null);
value = css ? css.getpropertyvalue(style) : null;
} else if (element.currentstyle) {
value = element.currentstyle[style];
}
}
/** dgf necessary?
if (window.opera && ['left', 'top', 'right', 'bottom'].include(style))
if (element.getstyle(element, 'position') == 'static') value = 'auto'; */
return value == 'auto' ? null : value;
}
注:选定的dom元素以color颜色高亮0.2s
复制代码 代码如下:
function uiwebhighlight(element,color) {
if (!element) {return}
var highlightcolor = yellow;
if (color) {highlightcolor = color}
if (element.originalcolor == undefined) { // avoid picking up highlight
element.originalcolor = elementgetstyle(element, background-color);
}
elementsetstyle(element, {backgroundcolor : highlightcolor});
window.settimeout(function () {
try {
//if element is orphan, probably page of it has already gone, so ignore
if (!element.parentnode) {
return;
}
elementsetstyle(element, { backgroundcolor: element.originalcolor });
} catch (e) { } // dgf unhighlighting is very dangerous and low priority
}, 200);
}
其它类似信息

推荐信息