Js查漏补缺05-函数

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>

<!--比较两个数的最大值和最小值的函数方法-->

<!--两种常用的声明函数的方式-->


<!--其实就是Js特有的匿名函数的用法-->
    var Min_Number=function(x,y){
        if(x<y){
            document.write(x+"是最小值");
        }else if(x>y){
            document.write(y+"是最小值");
        }else{
            document.write(x+""+y+"相等");
        }
        document.write("<br>");
    };

    function Max_Number(x,y){
        if(x>y){
            document.write(x+"是最大值");
        }else if(x<y){
            document.write(y+"是最大值");
        }else{
            document.write(x+""+y+"相等");
        }
        document.write("<br>");
    }

    var input1=prompt("请输入x");
    var input2=prompt("请输入y");
    Max_Number(input1,input2);
    Min_Number(input1,input2);



<!--Object对象调用内部成员方法-->
    var student={
        name:"wendy",
        age:20,
        shu1:100,
        shu2:200,
        max_number:function(a,b){
            document.write(a+b);
        }
    };
    student.max_number(student.shu1,student.shu2);


<!--遍历对象中的属性和方法-->
    for(var i in student){
        document.write(i);
        document.write(student[i]+"<br>");

    }


</script>
</body>
</html>

猜你喜欢

转载自www.cnblogs.com/cuijunfeng/p/13160756.html