作家
登录

js批量设置样式的三种方法不推荐使用with

作者: 来源:www.28hudong.com 2013-03-30 00:09:48 阅读 我要评论

一般我们都用css来批量设置样式,现在我们用js也可以批量设置样式: 总结三种方法如下 复制代码 代码如下: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题文档</title> <style type="text/css"> #div1{ width:100px; height:100px; background:#069;} </style> <script type="text/javascript"> //第一种使用JSON function setStyle(obj,json){ for(var i in json) { obj.style[i]=json[i]; } } window.onload=function(){ var oDiv=document.getElementById('div1'); // setStyle(oDiv, {width: '200px', background: 'red'}); //第一种 // oDiv.style.cssText="width: 200px; height:300px; background:yellow;"; //第二种 使用cssText   //使用第三种 with (不推荐使用) with(oDiv.style) { width='300px'; height='500px'; background='yellow'; } }; </script> </head> <body> <div id="div1"></div> </body> </html>

  推荐阅读

  JS关键字变色实现思路及代码

1.替换关键字,对字体变色 复制代码 代码如下: public static string ReplaceRed(string strtitle, string redkey) { if (redkey == "" || redkey == null) { return strtitle; } else strtitle = strtitle.Replac>>>详细阅读


本文标题:js批量设置样式的三种方法不推荐使用with

地址:http://www.17bianji.com/kaifa2/JS/22323.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)