每天一个JavaScript实例-展示设置和获取CSS样式设置
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>每天一个JavaScript实例-展示设置和获取CSS样式设置</title>
<style>
#date{
width:200px;
background-color:lime;
}
</style>
<script>
function getStyle(date,cssprop,cssprop2){
//IE
if(date.currentStyle){
return date.currentStyle[cssprop];
}else if(document.defaultView && document.defaultView.getComputedStyle){
//console.log(document.defaultView.getComputedStyle(date,null).getPropertyValue(cssprop));
return document.defaultView.getComputedStyle(date,null).getPropertyValue(cssprop2);
}else{
return null;
}
}
window.onload = function(){
var date = document.getElementById("date");
var color = getStyle(date,"background-color","background-color");
console.log(color);
date.style.width= "500px";
date.style.backgroundColor= "yellow";
console.log(date.style.width);
console.log(date.style.backgroundColor);
//数组表示法
date.style["fontFamily"] = "courier";
//展示覆盖属性
var style = date.getAttribute("style");
console.log(style); date.setAttribute("style","height:100px");
console.log(document.defaultView.getComputedStyle(date,null).getPropertyValue("fontFamily"));//null
console.log(document.defaultView.getComputedStyle(date,null).getPropertyValue("font-family"));//STHeiti var style = date.getAttribute("style"); //date.style["fontFamily"]="微软雅黑";
var font = getStyle(date,"fontFamily","font-family");
//console.log(font);
}
</script>
</head> <body> <div id = "date" style="color:purple">
aa
</div> </body>
</html>
每天一个JavaScript实例-展示设置和获取CSS样式设置的更多相关文章
- 使用jQuery设置和获取css样式
- js中获取css样式属性值
关于js中style,currentStyle和getComputedStyle几个注意的地方 (1)用js的style只能获取元素的内联样式,内部样式和外部样式使用style是获取不到的.针对css ...
- 每天一个JavaScript实例-获取元素当前高度
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- 每天一个JavaScript实例-从一个div元素删除一个段落
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- 每天一个JavaScript实例-推断图片是否载入完毕
<!doctype html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- 每天一个JavaScript实例-动态省份选择城市
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- 每天一个JavaScript实例-递归实现反转数组字符串
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- 每天一个JavaScript实例-html5拖拽
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- 每天一个JavaScript实例-canvas绘图
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
随机推荐
- Linux中tty框架与uart框架之间的调用关系剖析【转】
转自:http://developer.51cto.com/art/201209/357501.htm 之前本人在"从串口驱动的移植看linux2.6内核中的驱动模型 platform de ...
- 华为上机测试题(求亮灯数量-java)
PS:自己写的,自测试OK,供大家参考. /* 一条长廊里依次装有n(1 ≤ n ≤ 65535)盏电灯,从头到尾编号1.2.3.…n-1.n.每盏电灯由一个拉线开关控制.开始,电灯全部关着.有n个学 ...
- 关于Android攻击面
先对android整个攻击面有一个体系化的认识,有助于理清思路, 对今后的学习有很大的帮助. 什么是攻击向量:从语言语法的角度来说,是一个动词,描述用来执行攻击的方法,描述了攻击者如何到达并接触任意给 ...
- Jboss ESB简介及开发实例
一.Jboss ESB的简介 1. 什么是ESB. ESB的全称是Enterprise Service Bus,即企业服务总线.ESB是过去消息中间件的发展,ESB采用了“总线”这样一 ...
- CodeForces - 985F Isomorphic Strings
假如两个区间的26的字母出现的位置集合分别是 A1,B1,A2,B2,....., 我们再能找到一个排列p[] 使得 A[i] = B[p[i]] ,那么就可以成功映射了. 显然集合可以直接hash, ...
- Jenkins配置Publish Junit test result report(转)
参考这篇文章:http://www.yiibai.com/jenkins/jenkins_unit_testing.html 插件:JUnit Plugin
- SQL Server 2008 R2 Build List
By Steve Jones, 2014/09/30 (first published: 2010/05/25) This is a list of the builds for SQL Server ...
- 分布式数据库以及OS
http://blog.csdn.net/longronglin/article/category/230501
- DevExpress.XtraTreeList
1. DevExpress.XtraTreeList控件 将其简称为tree,tree其实就是一个树表控件,他像树一样包含具有父子关系的若干节点,同时每个节点又是一个带有多个字段的记录 ...
- Android ToolBar 使用完全解析
ToolBar简介 ToolBar是Android 5.0推出的一个新的导航控件用于取代之前的ActionBar,由于其高度的可定制性.灵活性.具有Material Design风格等优点,越来越多的 ...