<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head><meta forua="true" http-equiv="Cache-Control" content="max-age=0" /></head>
<card title="JS中style属性" id="card1">
<p> 游客</p><p>
标题:JS中style属性<br/>
正文:<br/>
JS中style属性现在我需要对这个标签赋值，其内容为： 1、需要显示的字为&amp;ldquo;HELLO WORLD&amp;rdquo;； 2、span的 background-color : red ，另外还要：border:1px solid #333333;cursor:hand; 我需要在&amp;lt;script&amp;gt;&amp;lt;/script&amp;gt;内把他们赋值，请问怎么写呢？难道要： document.getElementById(&amp;quot;a&amp;quot;).style.background=&amp;quot;red&amp;quot;; 来一项一项的写？ 能不能一下子把style写完啊，怎么写啊？ 解决办法：1、先定义一个CSS规则，然后this.className=’’2、document.getElementById(&amp;quot;a&amp;quot;).style.cssText=&amp;quot;border-collapse:collapse;border-spacing:1;border:1 solid #0B2565;background-color:white;color:black;&amp;quot; JS操作css的float属性的特殊写法使用js操作css属性的写法是有一定的规律的：1、对于没有中划线的css属性一般直接使用style.属性名即可。如：obj.style.margin，obj.style.width，obj.style.left，obj.style.position等。2、对于含有中划线的css属性，将每个中划线去掉并将每个中划线后的第一个字符换成大写即可。如：obj.style.marginTop，obj.style.borderLeftWidth，obj.style.zIndex，obj.style.fontFamily等。这个规律我想大多数的前端开发者也都熟知。但在css中有一个特殊的属性其js使用方法比较特殊。这个特殊的属性就是:float。我们不能直接使用obj.style.float来使用，这样操作是无效的。其正确的使用方法是为：IE:obj.style.styleFloat，其他浏览器:obj.style.cssFloat。<br/><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=333&amp;Page=1">[&lt;&lt;]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=333&amp;Page=1">[[1]]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=333&amp;Page=1">[&gt;&gt;]</a><br/>
<br/>
<a href="wap.asp?act=Com&amp;id=333">查看评论(0)</a><br/>
<a href="wap.asp?act=AddCom&amp;inpId=333">发表评论</a><br/><br/>

<br/>

<br/>
<a href="http://camnpr.com/wap.asp">首页</a>
</p>
</card>
</wml>