15 获取运行时的style 属性值
来源:互联网 发布:如何提高免疫力 知乎 编辑:程序博客网 时间:2024/04/29 12:11
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>14操作对象</title>
<style>
div{
height: 300px;
width: 300px;
border-bottom: 1px solid pink;
}
#test1{
background: red;
}
#test2{
background: yellow;
}
</style>
</head>
<body>
<div id="test1" onclick='t();'></div>
</body>
<script>
//indexof 查找字符串出现 找不到返回-1
//getComputedStyle() 第二参 伪类 一般填null
//currenstyle 或 是否能获取obj的属性
//currenstyle 或 getComputedStyle()只能读取值不能修改值
function getstyle(obj,src){
return obj.currentStyle ? obj.currentStyle[src]:getComputedStyle(obj, null)[src];
}
function t() {
var a = document.getElementsByTagName("div")[0];
if (a.id.indexOf('test1')>=0) {
a.id = 'test2';
} else {
a.id = 'test1';
}
a.style.height = parseInt(getstyle(a,'height')) + 5 + 'px';
a.style.width = parseInt(getstyle(a,'width')) + 5 + 'px';
a.style.borderBottomWidth = parseInt(getstyle(a,'borderBottomWidth'))+1+'px';
}
</script>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>14操作对象</title>
<style>
div{
height: 300px;
width: 300px;
border-bottom: 1px solid pink;
}
#test1{
background: red;
}
#test2{
background: yellow;
}
</style>
</head>
<body>
<div id="test1" onclick='t();'></div>
</body>
<script>
//indexof 查找字符串出现 找不到返回-1
//getComputedStyle() 第二参 伪类 一般填null
//currenstyle 或 是否能获取obj的属性
//currenstyle 或 getComputedStyle()只能读取值不能修改值
function getstyle(obj,src){
return obj.currentStyle ? obj.currentStyle[src]:getComputedStyle(obj, null)[src];
}
function t() {
var a = document.getElementsByTagName("div")[0];
if (a.id.indexOf('test1')>=0) {
a.id = 'test2';
} else {
a.id = 'test1';
}
a.style.height = parseInt(getstyle(a,'height')) + 5 + 'px';
a.style.width = parseInt(getstyle(a,'width')) + 5 + 'px';
a.style.borderBottomWidth = parseInt(getstyle(a,'borderBottomWidth'))+1+'px';
}
</script>
</html>
----------------------------------------------------------------------------------------------------
0 0
- 15 获取运行时的style 属性值
- JavaScript操作对象以及获取运行时的style对象
- JavaScript操作对象以及获取运行时的style对象
- js获取非style的css属性
- 原生JS获取内嵌,外部css样式,使用style只能直接获取内联style的属性值
- 无法获取未定义或null引用的属性“style”
- 获取到某个元素的某个style中的属性。
- 运行时获取属性列表
- 运行时 获取属性列表
- JavaScript / jQuery 设置、获取元素属性 值 设置style样式
- style中position的属性值详解
- style中position的属性值详解
- list-style-type的属性值
- Style的所有属性
- div.style的属性
- iOS 运行时获取类的所有属性
- 通过运行时获取某个类下所有的属性
- 运行时简单使用-->获取对象的属性(class_copyIvarList)
- uva 12230
- HDU4664 Triangulation sg函数
- 【egret】Tween类
- Android Studio的自动提示功能忽略大小写敏感
- php 计算出一年中每周的周一日期
- 15 获取运行时的style 属性值
- codeforces 618D. Hamiltonian Spanning Tree
- C++中函数返回临时对象和本地对象的区别
- 数组
- 项目实战--项目介绍
- centos7 安装ssh扩展控制linux
- STL中提供-二分查找算法(binary_search lower_bound upper_bound equal_range)
- ARM上电取第一条指令流程
- poj2632 Crashing Robots