当前位置:编程学习 > JAVA >>

javascript学习实录 之一 --刘啸尘

突然想系统的学习一下javascript,花了几个小时思考,该如何学习,制定下学习计划,说做就做,走 走

废话我就不说了,像javascript的由来啊,什么的等等,自己百度/google吧,先来一段javascript,最基本的排序操作


[javascript]
<html> 
    <title></title> 
    <head> 
        <script type="text/javascript"> 
            var arr = [3, 1, 5, 8, 2, 9, 4]; 
            function sortArr(arr) { 
                for (var i = 0; i <= arr.length; i++) { 
                    for(var j = i+1; j <= arr.length; j++) { 
                        if(arr[i] > arr[j]) { 
                            var temp = arr[i]; 
                            arr[i] = arr[j]; 
                            arr[j] = temp; 
                        }                        
                    } 
                } 
                return arr; 
            } 
                 
            alert(sortArr(arr)); 
        </script> 
    </head> 
 
    <body> 
         
    </body> 
</html> 

<html>
 <title></title>
 <head>
  <script type="text/javascript">
   var arr = [3, 1, 5, 8, 2, 9, 4];
   function sortArr(arr) {
    for (var i = 0; i <= arr.length; i++) {
     for(var j = i+1; j <= arr.length; j++) {
      if(arr[i] > arr[j]) {
       var temp = arr[i];
       arr[i] = arr[j];
       arr[j] = temp;
      }      
     }
    }
    return arr;
   }
    
   alert(sortArr(arr));
  </script>
 </head>

 <body>
  
 </body>
</html>
以上是个排序的代码,跟java的比较类似,看看都能懂,so easy。

你还可以写成如下形式


[javascript]
var sortArr2 = function(arr) { 
                for (var i = 0; i <= arr.length; i++) { 
                    for(var j = i+1; j <= arr.length; j++) { 
                        if(arr[i] > arr[j]) { 
                            var temp = arr[i]; 
                            arr[i] = arr[j]; 
                            arr[j] = temp; 
                        } 
                    } 
                } 
                return arr; 
            } 
            alert(sortArr2(arr)); 

var sortArr2 = function(arr) {
                for (var i = 0; i <= arr.length; i++) {
                    for(var j = i+1; j <= arr.length; j++) {
                        if(arr[i] > arr[j]) {
                            var temp = arr[i];
                            arr[i] = arr[j];
                            arr[j] = temp;
                        }
                    }
                }
                return arr;
            }
            alert(sortArr2(arr));
来看一下下面这个函数


[javascript]
function fuc(x, y, z) { 
   alert(x + ",," + y + ",," + z); 

fuc(1, 2, 4) 

function fuc(x, y, z) {
   al

补充:web前端 , JavaScript ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,