zoukankan      html  css  js  c++  java
  • js---06函数传参数

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    
    <script>
    /*
        参数=JS的数据类型:
            数字、字符串、布尔、函数、对象、未定义
    */
    
    fn2('妙味课堂');
    function fn2(a){
        alert(a.charAt(2));
    }
    
    function fn4(){
        alert(4);
    }
    function fn3( fn ){
        fn();
    }
    fn3( fn4 );
    
    function fn3( fn ){
        fn(100);
    }
    fn3( function ( a ){ alert(a); } );//a=100
    
    fn5( window, document );
    function fn5( w, d ){
        w.onload = function (){
            d.body.innerHTML = 123;
        };
    }
    
    </script>
    
    </head>
    
    <body>
    </body>
    </html>
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    
    <script>
    
    function fn1(a){
        if( typeof a === 'number' && a === a ){//a === a,NaN也是数字类型,NaN不等于自己,这是排除NaN
            alert( a+20 );
        } else if ( typeof a === 'string' ) {
            alert( a.charAt(2) );
        } else if ( typeof a === 'function' ) {
            a(100);//alert(101)
        }
    }
    
    fn1(100);
    fn1('miaov');
    fn1(function (arr){ alert(1+arr); });
    </script>
    
    </head>
    
    <body>
    </body>
    </html>
  • 相关阅读:
    Roadblocks(poj 3255)
    最小集合(51nod 1616)
    绿色通道(codevs 3342)
    解的个数(codevs 1213)
    多米诺(codevs 3052)
    abcd
    dwarf tower
    第K 小数
    noip2016复习
    文化之旅(洛谷 1078)
  • 原文地址:https://www.cnblogs.com/yaowen/p/6828757.html
Copyright © 2011-2022 走看看