css样式获取及兼容性(原生js)

news/2024/7/19 14:37:20 标签: css, js

类选择器兼容性
              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]")

 

  


http://www.niftyadmin.cn/n/1733267.html

相关文章

NetBeans快捷键与Eclipse快捷键比较

http://developer.51cto.com 2009-06-16 13:53 佚名 zdnet.com 我要评论(0)摘要&#xff1a;本文简要介绍netbeans快捷键与Eclipse快捷键的比较&#xff0c;这里主要是针对NetBeans 6.0正式版。快捷键是大家使用较多的东西&#xff0c;希望这个对比能对大家有所帮助。标签&…

SpringCloud——注册中心nacos

四、Nacos注册中心 4.1 初识Nacos Nacos是阿里巴巴的产品&#xff0c;也是目前SpringCloud的一个组件&#xff0c;相比Eureka而言&#xff0c;功能更加丰富&#xff0c;在国内受欢迎的程度也更高。 Nacos是需要下载的&#xff0c;Windows下载教程如下&#xff1a; 这是我在…

I'll be there--Jackson Five

Ill be there--Jackson FiveWhenever you need me, Ill be there. Ill be there to protect you,with an unselfish love I respect you .Just call my name and Ill be there.

树莓派串口连接ESP8266

陈拓 chentuoms.xab.ac.cn 2020/03/12-2020/03/12 1. 概述 ESP8266是物联网行业广泛使用的WiFi模块&#xff0c;小巧、功能强大&#xff0c;而且价格低廉。通常用电脑进行ESP8266开发时需要一个USB-串口转换器&#xff0c;如果你手边刚好有一块树莓派&#xff0c;就可以用树莓…

SpringCloud——Http客户端Feign

五、http客户端Feign 5.1 初识Feign 前面我们使用远程调用一直用的都是RestTemplate对象来发送请求&#xff0c;源码如下&#xff1a; String url "http://user/user/"order.getUserId(); User user restTemplate.getForObject(url, User.class);这种写法&#…

chm格式文件打开出错:无法显示网页 已解决

chm格式文件打开出错&#xff1a;无法显示网页 已解决 [ 2006-07-27 16:02:27 | Author: YiitoBlog ] Font Size: Large | Medium | Small 最近在为系统制作帮助&#xff0c;前几天搞定了 用word文档批量制作chm文件的方法 现在有一个子系统的chm帮助文件&#xff0c;需要提供客…

树莓派安装ESP8266 NON-OS SDK开发环境

陈拓 chentuoms.xab.ac.cn 2020/02/19-2020/03/31 1. 概述 ESP8266的开发工具是在linux系统下运行的&#xff0c;树莓派的官方操作系统是Linux系统。如果你手头刚好有一块树莓派&#xff0c;就可以用它进行ESP8266的开发。下面我们在树莓派3B上安装ESP8266的开发环境。所用的…

SpringCloud——网关Gateway

文章目录六、统一网关 Gateway6.1 网关介绍6.2 快速搭建网关6.3 断言工厂6.4 过滤器工厂6.5 全局过滤器 GlobalFIlter6.6 过滤器的执行顺序6.7. 跨域问题六、统一网关 Gateway 6.1 网关介绍 Spring Cloud Gateway 是 Spring Cloud 的一个全新项目&#xff0c;该项目是基于 Sp…