javascript如何改变cssText

1.改变cssText

例 2.1

<HTML>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
</HEAD>
<BODY>
<SPAN ID="a" STYLE="ONE</SPAN>
<SPAN ID="b" STYLE="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>

更多内容请见原文,文章转载自:https://blog.csdn.net/qq_43650923/article/details/102805095

posted @ 2021-11-24 19:41  malala  阅读(65)  评论(0编辑  收藏  举报