javascript如何改变cssText

马克- to-win:马克 java社区:防盗版实名手机尾号: 73203。



例 2.1

<HTML>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
</HEAD>
<BODY>
<SPAN ID="a" STYLE="background-color:RED">ONE</SPAN>
<SPAN ID="b" STYLE="background-color:BLUE">TWO</SPAN>

<FORM>
    <INPUT TYPE="button" VALUE="点 ME" onClick="clickMe()">
</FORM>
<SCRIPT>

    function clickMe()
    {
        var mySp = document.getElementsByTagName("SPAN");
        /*
         style.cssText (Property)
         The CSS style sheet specification source text for this style object.
         Property/method value type: String primitive
         JavaScript syntax: IE myStyle.cssText
         the following statement's result is mySpans[mySpans.length-1].style.cssText="background-color:BLUE"
         */
        mySt1 = mySp[mySp.length-1].style.cssText;
//alert( "mySpans[mySpans.length-1].style.cssText is"+mySpans[mySpans.length-1].style.cssText);
        mySp[0].style.cssText = mySt1;
    }
</SCRIPT>
</BODY>
</HTML>