猿问

js三目运算报错问题,求指点。不要麻烦if,谢谢各位老师。

<!DOCTYPE html>

<html>

<head>

<title>音乐</title>

<meta charset="utf-8">

<meta name="kewords" content="在线听歌,流行音乐,伤感音乐">

<meta name="descriptions" content="听音乐,听音乐。我是音乐,我是音乐">

<meta name="robots" content="all">

<!-- <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, maximum-scale=1, minimun-scale=1"> -->

<!-- <meta name="viewport" content="initial-scale=1, maximum-scale=3, minimum-scale=1, user-scalable=no"> -->

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">

<meta name="apple-mobile-web-app-capable" content="yes">

<meta name="apple-mobile-web-app-status-bar-style" content="cyan">

<meta name="HandeldFriendly" content="true">

<meta name="format-detection" content="telephone=no">

<meta name="author" content="oyb">

<style>

*{

margin:0;

padding:0;

box-sizing: border-box;

list-style: none;

}

.box{

width:80%;

height:200px;

margin:100px auto;

border:1px solid #ddd;

display:-webkit-flex;

display:-webkit-box;

display:flex;

justify-content: space-between;

-webkit-justify-content: space-between;


}

.box .item{

width:50px;

height:80px;

background:lightcyan;

border:1px solid red;

}

</style>

</head>

<body>

<div class="box" id="box">

<div class="item">1212</div>

<div class="item" id="two"></div>

<div class="item">1212</div>

<div class="item">aas</div>

<div class="item">ggg</div>

</div>

<script>

var getT={};

getT.now=function(testDate){

//console.log(new Date)

var now=new Date;

return now;

}

getT.Week=function(testDate){

//testDate必须是整数型的

var now=testDate||((new Date()).getDay());

var result;

switch(now)

{

case 0:

result="周日"

break;

case 1:

result="周一"

break;

case 2:

result="周二"

break;

case 3:

result="周三"

break;

case 4:

result="周四"

break;


case 5:

result="周五"

break;

case 6:

result="周六"

break;

}


return result;

}


getT.time=function(habit){

var h=this.now().getHours();

var m=this.now().getMinutes();

if(habit=="习惯"){

var _h=

(h<12) ? return ("上午 "+_h+":"+m): ("下午 "+_h+":"+m)//test-flex.html:104 Uncaught SyntaxError: Unexpected token return

//想法:当小时数h大于12点时就返回“上午 xx点:xx分”,小天12点也是类似这样的情况,现在我不知道我的js三目运算法哪里错了,能不用if 就要用,希望各位大神能指点下。

}

return h+":"+m;

}

getT.date=function(){

var m=this.now().getMonth();

var d=this.now().getDate();

return (m+1)+"月"+d+"日"

}

var box=document.getElementById("box");

//console.log(two);

//console.log(box.innerHTML);

box.innerHTML=getT.time("习惯");

</script>

</body>

</html>


慕前端8664132
浏览 2020回答 3
3回答

风筝_0010

这个报错很明显了。。你那个return是什么鬼

慕前端8664132

以上代码直接运行就可以看到控制日志里的错误了。
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答