JavaScript中批量设置Css样式

2020-05-07 13:05:28

设置 input 元素的  属性:

document.getElementsByTagName("INPUT")[0].setAttribute("属性","属性内容");

定义和用法

setAttribute() 方法添加指定的属性,并为其赋指定的值。

如果这个指定的属性已存在,则仅设置/更改值

当然也可以批量修改属性

var dom=document.getElementById("id"); 
dom.setAttribute("style","width:10px;height:10px;border:solid 1px red;") ; 

IE中则必须使用style.cssText 

var dom=document.getElementById("id"); 
dom1.style.cssText = "width:10px;height:10px;border:solid 1px red;"; 


  • 2017-02-24 16:53:58

    PHP 中的Closure

    Closure,匿名函数,又称为Anonymous functions,是php5.3的时候引入的。匿名函数就是没有定义名字的函数。这点牢牢记住就能理解匿名函数的定义了。

  • 2017-03-02 09:45:27

    动态加载js和css

    开发过程中经常需要动态加载js和css,今天特意总结了一下常用的方法。