为了账号安全,请及时绑定邮箱和手机立即绑定

正在回答

4 回答

switch必须附初始值吧

0 回复 有任何疑惑可以回复我~

case后面是常量表达式。

<!DOCTYPE  HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>函数</title>
<script type="text/javascript">
//定义函数
function compare(a,b){
    var max = a > b?a:b;
    return max;
//函数体,判断两个整数比较的三种情况
}
 
//调用函数,实现下面两组数中,返回就大值。
  document.write(" 5 和 4 的较大值是:"+compare(5,4)+"<br>");
  document.write(" 6 和 3 的较大值是:"+ compare(6,3) ); 
</script>
</head>
<body>
</body>
</html>


1 回复 有任何疑惑可以回复我~
#1

snicker

a>b?a:b这是什么意思,求解
2015-02-05 回复 有任何疑惑可以回复我~
#2

_潇潇暮雨 回复 snicker

三目运算符,相当于 var max; if(a>b){ max = a; }else{ max = b; }
2015-02-05 回复 有任何疑惑可以回复我~

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>函数</title>

<script type="text/javascript">

  function fbijiao(a,b){

     if((a-b)>0){

    return a;

     }else if((a-b)<0){

    return b;

     }else{

    return "相等";

     }

  }  

  document.write(" 5 和 4 的较大值是:"+fbijiao(5,4)+"<br>");

  document.write(" 6 和 6 的较大值是:" +fbijiao(6,6)); 





</script>

</head>

<body>


0 回复 有任何疑惑可以回复我~

case 后面只能跟个确定值,不可以跟判断语句

1 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信