javascript 基礎3第13節

來源:互聯網
上載者:User

標籤:

<html><head><title>javascript基礎</title></head><body>1.流程式控制制  順序  選擇  迴圈結構<br/><script type="text/javascript">   var  score = 50;/* 多行注釋if ( score > 60 ){alert("恭喜,及格了...");}*/// if ... else ...    單行注釋// if ...  else if  .... else if .... else ...//switch//  ?   : document.write("成績是否合格 :  " , score > 60 ? ‘及格‘:‘沒通過‘  ,"<br/>");// while// do while//for( ; ;)         break   continue  之後的代碼不執行</script>2.數組<br/><script type="text/javascript"> var  a = new Array();//建立數組  沒有長度  沒有類型限制  set  list document.write("a數組的長度 :  " , a.length  ,"<br/>"); a[0] = 12; a[1] = 5; a[10] = 35; a[2] = ‘張三‘; a[5] = new Date(); document.write("a數組的長度 :  " , a.length  ,"<br/>"); document.write("a數組的元素 :  " , a.toString()  ,"<br/>"); var b = new Array(3); document.write("b數組的長度 :  " , b.length  ,"<br/>"); b[5] = 100; document.write("b數組的長度 :  " , b.length  ,"<br/>"); document.write("b數組的元素 :  " , b ,"<br/>"); //a = new Array(5); a.length = 5;//修改長度 document.write("a數組的元素 :  " , a ,"<br/>"); //初始化 var colors = new Array(‘red‘,‘yellow‘,‘blue‘,‘green‘,‘white‘,‘black‘); colors[6] = "gray"; document.write("colors數組的元素 :  " , colors ,"<br/>"); /* for(var i = 0; i < colors.length; i++ ) {   document.write(i , "  :  " , colors[i] ,"<br/>");                        } 增強for迴圈 for(var i in colors) {  document.write( i , "  :  " , colors[i] , "<br/>"); // i 數組索引    } */var  c = [, new Object , , ‘a‘,new Number(80),"yema"];c[0] = 20;c[1] = 10;c[2] = 30;document.write("c是否是數組  :  " , c instanceof Array , "<br/>");document.write("c數組的元素 :  " , c ,"<br/>");</script>     3.數組的方法<br/><script type="text/javascript">document.write("colors.concat(c) :  " , colors.concat(c) ,"<br/>");document.write("colors.join(‘->‘) :  " , colors.join(‘->‘) ,"<br/>");document.write("colors.pop() :  " , colors.pop() ,"<br/>");colors.push(‘abcd‘);document.write("colors :  " , colors ,"<br/>");document.write("colors.shift() :  " , colors.shift() ,"<br/>");colors.unshift(‘oracle‘);document.write("colors :  " , colors ,"<br/>");document.write("colors.reverse() :  " , colors.reverse() ,"<br/>");document.write("colors.sort() :  " , colors.sort() ,"<br/>");var  d = [11,2,6,34] document.write("d.sort() :  " , d.sort() ,"<br/>");  document.write("colors.slice(2,5) :  " , colors.slice(2,5) ,"<br/>");document.write("======================== <br/>"); //splice document.write("colors :  " , colors ,"<br/>");colors .splice(1,2);//刪除document.write("colors :  " , colors ,"<br/>");colors.splice(3,0,‘java‘,‘xml‘);//添加document.write("colors :  " , colors ,"<br/>");colors.splice(1,2,‘football‘,‘swim‘);//修改document.write("colors :  " , colors ,"<br/>");</script>     </body></html>

 rs:

javascript 基礎3第13節

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.