JavaScript學習歷程03

一閃一閃亮晶晶javascript

<script type="text/javascript">
        var nn = Number(prompt('請輸入一個1-9的正整數!'));
        var n =nn;
        var num=n;
        var star="*";
        // document.write(num01);
        for (var i = 0; i < n; i++) {
            
            for (var j = 0; j < num; j++) {
                document.write(star)
                
            }
            --num;
            document.write(n);
            document.write("<br />");
        }
        n =nn;
        for (var i = 1; i < n; i++) {
            
            for (var j = 0; j < i+1; j++) {
                document.write(star)
                
            }
            document.write(n);
            document.write("<br />");
        }

    </script>

 

window對 圖片自動切換 要求:使用延時器和定時器來製做。java

<script type="text/javascript">
    var i=0;
    window.onload=function()
    {
        window.setInterval(Getimg,100);
    }
    function Getimg()
    {
        ++i
        var imgObj=document.getElementById("imgId");
        imgObj.src="images/dd_scroll_"+i+".jpg";
        if (i==6) 
        {
            i=0;
        }
    }
    </script>
</head>
<body>
<img id="imgId" src="" />    
</body>

 

點出滿天小星星app

<script type="text/javascript">
    function start2(e)
    {
        var x=e.clientX;
        // document.write(x);
        var y=e.clientY;
        // document.write(y);

        // 建立節點
        var imgObj=document.createElement("img");
        // 掛載節點 
        document.body.appendChild(imgObj);
     
        imgObj.src="1.png";
        imgObj.width=getRandom(20,50);
        imgObj.style.position = "absolute";
        imgObj.style.left = x-imgObj.width/2 + "px";
        imgObj.style.top = y-imgObj.width/2 + "px";

        
        // imgObj.style.left=
    }
    function getRandom(min,max)
    {
        var random=Math.random()*(max-min)+min;
        return random;
    }

        
    </script>
相關文章
相關標籤/搜索