手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >JS.elementGetStyle(element, style)应用示例
JS.elementGetStyle(element, style)应用示例
摘要:注:获取Dom元素的Style数组中的指定Style元素复制代码代码如下:functionelementGetStyle(element,s...

注: 获取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);

}

【JS.elementGetStyle(element, style)应用示例】相关文章:

精彩图片推荐 渐隐渐现

js事件监听器用法实例详解

可输入的下拉框

JS中字符串trim()使用示例

JavaScript获取两个数组交集的方法

jQuery zTree加载树形菜单功能

对textarea框的代码调试,而且功能上使用非常方便,酷

js输入中文效果

显示行号的文本输入框

JQUERY表单暂存功能插件分享

精品推荐
分类导航