css样式获取及兼容性(原生js)
2024-10-19 18:25:57
类选择器兼容性
getbyclass()类选择器,在IE8及以下均不可用。 // 类选择器的兼容性
function getbyclass(parentName,Name){ var parentName=document.getElementById(parentName); // 通过标签名通配符选择所有父容器内的元素
var all=parentName.getElementsByTagName("*"); console.log(all); // 创建一个新数组用来接收body元素中满足条件的元素集合
var arr=new Array; for(var i=0;i<all.length;i++){ if (all[i].className==Name){arr.push(all[i]);} } return arr; } // 选择父容器
id var a=getbyclass("ddd","d"); console.log(a);
CSS行间样式的获取(并非属性)
var odiv=document.getElementById("div1");
alert(odiv.style.height);
CSS内部样式及外链样式的获取
var odiv=document.getElementById("div1");
var a=odiv.currentStyle;
// console.log(odiv.style.cssText);
alert(odiv.currentStyle.width);//IE浏览器
var cssodiv=window.getComputedStyle(odiv); alert(cssodiv.width);//主流浏览器 // 兼容IE和主流浏览器:
function getcssstyle(obj){
if(window.getComputedStyle){return window.getComputedStyle(obj);}//IE9及以上支持,一下为undified
else{return obj.currentStyle;}}//IE浏览器 var odivcss=getcssstyle(odiv);
alert(odivcss.width);
css样式设置
oDiv.style.backgroundColor="";
oDiv[style][backgroundColor]="";
// 方括号一般用在传参的时候(否则系统会把参数当成属性)比如:
function(Name,red){document[name][backgroundColor]=red}
css属性选择器
var li=document.querySelectorAll("li");
var li=document.querySelector("li");
var btn=document.querySelector("input[type=button]")
最新文章
- Django 浏览页面点击计数(通用视图)
- 一点一滴学shell-Shell expr的用法 (转)
- 深入理解PHP内核(七)变量及数据类型-常量
- 神经网络dropout
- android-ListView控件的使用
- 命名空间std引用<;iostream>;时使用
- java学习笔记 (1) —— Strut2.3.24环境搭建
- Oracle 转换函数
- QlikView一年计算,以最新的销售数据
- android使用TextView实现跑马灯的效果(1)
- WPF中使用USERCONTROL
- 测试对bug如何分析和定位
- IDEA+MySQL实现登录注册的注册验证时出现 Cannot resolve query parameter &#39;2&#39;
- angular4脚手架搭建
- ES6 扩展运算符
- Oracle PL/SQL,游标,过程
- VMware Authorization Service不能启动 VMware虚拟机状态已挂起无法恢复解决方案
- pixi.js v5 快速了解
- java.lang.IllegalArgumentException: Request header is too large 解决方案
- python类可以任意添加属性
热门文章
- apple applessd.sys error
- omnidazzle是mac的画笔工具
- Unity3D 游戏引擎之C#使用Socket与HTTP连接server数据传输包
- 关于使用data()获取自定义属性出现undefined的说明
- DirectX11 学习笔记7 - 支持自由移动的摄像机
- 【图像处理】基于OpenCV底层实现的图片旋转
- OpenCV 2.4.8 or OpenCV 2.4.9组件结构全解
- CCBPM工作流引擎的消息机制与设计
- [计算机故障处理]EXCEL文件双击不能直接打开
- go语言---传值和传引用