问答详情
源自:4-3 [JavaScript]属性操作

求大神指点哪里错了?

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=gd2312">
        <title>制作我的第一个网页</title>
    </head>
    <body>
        <h1>标题1</h1>
     
        <script language="javascript">
                        <form name="name1"method="post" action="">
         <input name="submit"type="button"value="更换背景颜色"onclick="turncolour();"><!--这是插入一个按键-->
       
           </form>
        var arraycolour=new Array("olive","teal","red","blue","maroon","green","yellow");    <!--定义一个颜色数组-->
        var n=0;
        function turncolour()                                                         <!--函数完成颜色变换-->                                       
        {
        if(n==(arraycolour.length-1)) n=1;
        n++;
        document.bgColor=arraycolour[n];
         }
        </script>
    </body>
</html>

http://img3.mukewang.com/59ba90d80001244a10480590.jpg

提问者:慕斯卡5410818 2017-09-14 22:23

个回答

  • qq_恋懿_0
    2017-09-15 00:27:45
    已采纳

    是不是实现变色啊!你把form的写在<script></script>中了,把他放在外面就可以了!

    <!DOCTYPE HTML>

    <html>

        <head>

            <meta http-equiv="Content-Type" content="text/html; charset=gd2312">

            <title>制作我的第一个网页</title>

        </head>

        <body>

            <h1>标题1</h1>

             <form name="name1"method="post" action="">

             <input name="submit"type="button"value="更换背景颜色"onclick="turncolour();"><!--这是插入一个按键-->

            </form>

            <script language="javascript">

            var arraycolour=new Array("olive","teal","red","blue","maroon","green","yellow");    <!--定义一个颜色数组-->

            var n=0;

            function turncolour()                                                         <!--函数完成颜色变换-->                                       

            {

            if(n==(arraycolour.length-1)) n=1;

            n++;

            document.bgColor=arraycolour[n];

             }

            </script>

        </body>

    </html>


  • qq_恋懿_0
    2017-09-15 00:10:25

    你的告诉别人要实现什么