想做一个图片切换的JS 看到这句三元运算符不明白是什么意思
<!doctypehtml><htmllang="en"><head><metacharset="utf-8"/><title>Auto-PlayingSlideshow...
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Auto-Playing Slideshow | jquerydemo.com</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="photos">
<img src="images/in-the-outfield.jpg"/>
<img src="images/ballpark-scoreboard.jpg" />
<img src="images/batting-helmets.jpg" />
<img src="images/baseball-in-glove.jpg" />
</div>
<script src="js/lib/jquery-1.9.0.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#photos img:gt(0)").hide();
setInterval(function() {
var current = $('#photos img:visible');
var next = current.next().length ? current.next() : $('#photos img:eq(0)');
current.fadeOut();
next.fadeIn();
}, 3000);
});
</script>
var next = current.next().length ? current.next() : $('#photos img:eq(0)');这个三元运算符 curren.next().length 不是要有条件判断吗?他这样写是什么意思 展开
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Auto-Playing Slideshow | jquerydemo.com</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="photos">
<img src="images/in-the-outfield.jpg"/>
<img src="images/ballpark-scoreboard.jpg" />
<img src="images/batting-helmets.jpg" />
<img src="images/baseball-in-glove.jpg" />
</div>
<script src="js/lib/jquery-1.9.0.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#photos img:gt(0)").hide();
setInterval(function() {
var current = $('#photos img:visible');
var next = current.next().length ? current.next() : $('#photos img:eq(0)');
current.fadeOut();
next.fadeIn();
}, 3000);
});
</script>
var next = current.next().length ? current.next() : $('#photos img:eq(0)');这个三元运算符 curren.next().length 不是要有条件判断吗?他这样写是什么意思 展开
3个回答
展开全部
current.next().length就是判断这个值是不是存在把。如果存在current.next().length就是大于等于1了,不存在就为0.
希望对你有用!
希望对你有用!
追答
解决了吗
已通知提问者对您的回答进行评价,请稍等
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询