JavaScript入門第三天

來源:互聯網
上載者:User

標籤:title   aaa   nts   png   隔行變色   htm   img   java   ack   

閉包:子函數可以使用父函數的局部變數
<html>    <head>        <title>閉包    </title>    <script>        function aaa(){//父函數            var a=12;                 function bbb(){//子函數  閉包  可以引用父函數的局部變數                 alert(a);                         }                bbb();        }        aaa();    </script>    </head>    <body>         </body></html>

 

 

隔行變色

<html>    <head>        <title>隔行變色    </title>    <script>        window.onload=function(){            var aLi=document.getElementsByTagName(‘li‘);            for(var i=0;i<aLi.length;i++){             //i 0 1 2 3 4 5 ...                if(i%2==0){                    aLi[i].style.background=‘grey‘;                }                else aLi[i].style.background=‘‘;            }        }    </script>    </head>    <body>     <ul>            <li></li>            <li></li>            <li></li>            <li></li>                    <li></li>            <li></li>                    <li></li>                    <li></li>            <li></li>     </ul>    </body></html>

 

分秒轉換器

<html>    <head>        <title>分秒轉換器    </title>    <script>        var s=1137;        alert(parseInt(s/60)+‘分‘+s%60+‘秒‘);    </script>    </head>    <body>    </body></html>

switch語句

 

 

<html>    <head>        <title>switch語句</title>    <script>        var name="張三";        var sex=‘男‘;        switch(sex){            case ‘男‘:            alert(name+‘先生,您好!‘);            break;            case ‘女‘:            alert(name+‘女士,您好!‘);            break;            default:            alert(name+‘您好!‘);}    </script>    </head>    <body>    </body></html>

三目運算子

條件?語句1:語句2

    <script>      var a=12;//判斷奇數偶數      a%2==0?alert("偶數"):alert("奇數");    </script>

 

JavaScript入門第三天

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.