码迷,mamicode.com
首页 > Web开发 > 详细

js 学习之路6: if...else...条件语句的使用

时间:2019-01-28 15:17:13      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:char   htm   条件语句   function   条件   charset   UNC   div   bsp   

1.1

if (...)

{

...

}

else

{

...

}

<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<body>

<script charset = "utf-8">

function myfunction(){
    var x = 11;
    var y = x % 2;
    document.write(y + "<br>");
    if (x % 2 == 1){
        document.write("单数");
    }
    else
    {
        document.write("双数");
    }
}

myfunction();

</script>

</body>
</html>

1.2

if (条件1)

{

...

}

else if (条件2)

{

...

}

else

{

...

}

<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<body>

<script charset = "utf-8">

function myfunction(x){
    var y = x % 2;
    if (x % 2 == 0){
        document.write("双数");
    }
    else if (x > 10)
    {
        document.write("大于10的单数");
    }
    else
    {
        document.write("普通单数");
    }
    
    document.write("<br>");
    document.write(x);
}

myfunction(15);

</script>

</body>
</html>

 

js 学习之路6: if...else...条件语句的使用

标签:char   htm   条件语句   function   条件   charset   UNC   div   bsp   

原文地址:https://www.cnblogs.com/zrmw/p/10329903.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!