每天一个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 ...
随机推荐
- 小知识:SPI四种模式区别【转】
转自:http://home.eeworld.com.cn/my/space-uid-80086-blogid-119198.html spi四种模式SPI的相位(CPHA)和极性(CPOL)分别可以 ...
- nginx 根据POST GET方法跳转
location ~ /server/ { proxy_pass_header Server; proxy_set_header Host $http_host; proxy_r ...
- 使用bottle进行web开发(2):http request
我们知道,http request有多个方法,比如get,post,delete,patch,put等.对用的,bottle都定义了相应的装饰器,目前定义了五个: get(),post(),put() ...
- VS2008中的配置文件app.config简单小结
应用程序的配置文件用于读取和保存简单的本地数据,vs中新增配置文件可以直接在项目的”属性“-”设置“里添加,添加后在项目的Properties文件夹会多出一组两个文件:Settings.setting ...
- Python的程序结构[3] -> 变量/Variable[0] -> 变量类型
变量类型 / Variable Type 在 Python 中,变量主要有以下几种,即全局变量,局部变量和内建变量, 全局变量 / Global Variable 通常定义于模块内部,大写变量名形式存 ...
- Python的网络编程[2] -> TFTP 协议[1] -> TFTP 的 Python 实现
TFTP实现 / TFTP Implement 目录 TFTP 的服务器建立过程 TFTP 的客户端建立过程 1 TFTP 的服务器建立过程 服务器建立步骤主要有: (1) 设定服务器IP和 ...
- 分析dump
一.使用jmap工具生成dump文件 二.MAT工具的下载和安装 三.使用MAT工具进行内存泄露分析 -- Step 1 : ps –ef | grep <process> (whic ...
- UITableView的横向使用
UITableView只支持竖向显示,要实现横向的显示,需要设置tableView 和cell 的transform属性为CGAffineTransformMakeRotate(-M_PI/2) // ...
- Bluetooth篇 开发实例之六 蓝牙RSSI计算距离
计算公式: d = 10^((abs(RSSI) - A) / (10 * n)) 其中: d - 计算所得距离 RSSI - 接收信号强度(负值) A - 发射端和接收端相隔1米时的信号强度 n - ...
- free 一个指针时【 retval = HeapFree(_crtheap, 0, pBlock);】报错的原因
报错的位置 void __cdecl _free_base (void * pBlock) { ; if (pBlock == NULL) return; RTCCALLBACK(_RTC_Free_ ...