function next(){
b?index++:index--;
(index==0 || index==len-1) && (b=!b);

startMove(-index*w);

}
这个函数里的
b?index++:index--;
(index==0 || index==len-1) && (b=!b);
求解....谢谢<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title> <style type="text/css">
*{margin:0;padding:0;}
ul{list-style:none outside none}
.slchanpin001{width:264px;}
.slchanpin001-t{height:30px;background:url(images/slpro001.jpg) no-repeat;width:264px;text-align:right;line-height:38px}
.slchanpin001-t a{color:#ff9f39;font-size:12px;margin-right:25px;}
.slchanpin001-c{width:264px;height:86px;overflow:hidden;background:url(images/slpro002.jpg) no-repeat;}
.slchanpin001-c li{float:left;width:244px;height:72px;}
.slchanpingCon01{height:72px;width:40000%;position:absolute;top:0;left:0;}
.slchanpin001-c01{position:relative;width:244px;height:72px;overflow:hidden;margin:4px auto 0;background:#fff;}
.slchanpingCon01-l{background:url(images/slpro003.jpg) no-repeat;width:66px;height:66px;float:left;margin:3px 0 0 4px;}
.slchanpingCon01-r{font-size:12px;width:165px;float:right;margin-top:10px}
.slchanpingCon01-r .slchanpingCon01-p1 a{color:#777777;font-weight:bold;text-decoration:none}
.slchanpingCon01-r p{line-height:18px}
.slchanpingCon01-links a{float:left; background:url(images/slpro004.jpg) no-repeat;width:69px;height:21px;text-align:center;text-decoration:none;line-height:21px;color:#777;}
</style> </head> <body> <div class="slchanpin001">
<div class="slchanpin001-t"><a href="">更多产品</a></div>
<div class="slchanpin001-c">
<div class="slchanpin001-c01"  id="slchanpin001-c01">
<div class="slchanpingCon01" id="slchanpingCon01">
<ul>
<li>
<div class="slchanpingCon01-l">
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="66" height="66" align="center" valign="middle"><img src="images/slpro005.jpg" /></td>
</tr>
</table>
</div> <div class="slchanpingCon01-r">
<p class="slchanpingCon01-p1"><a href="">金装智多多三文鱼营养面条</a></p>
<p>售价 <span style="font-weight:bold;color:#777">¥18.80</span></p>
<p class="slchanpingCon01-links"><a href="">产品详情</a>  <a href="">在线订购</a></p>
</div>
</li>
<li><div class="slchanpingCon01-l">
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="66" height="66" align="center" valign="middle"><img src="images/slpro005.jpg" /></td>
</tr>
</table>
</div> <div class="slchanpingCon01-r">
<p class="slchanpingCon01-p1"><a href="">金装智多多三文鱼营养面条</a></p>
<p>售价 <span style="font-weight:bold;color:#777">¥18.80</span></p>
<p class="slchanpingCon01-links"><a href="">产品详情</a>  <a href="">在线订购</a></p>
</div></li>
<li>
<div class="slchanpingCon01-l">
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="66" height="66" align="center" valign="middle"><img src="images/slpro005.jpg" /></td>
</tr>
</table>
</div> <div class="slchanpingCon01-r">
<p class="slchanpingCon01-p1"><a href="">金装智多多三文鱼营养面条3</a></p>
<p>售价 <span style="font-weight:bold;color:#777">¥18.80</span></p>
<p class="slchanpingCon01-links"><a href="">产品详情</a>  <a href="">在线订购</a></p>
</div>
</li>
<li>4</li>
<li>
<div class="slchanpingCon01-l">
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="66" height="66" align="center" valign="middle"><img src="images/slpro005.jpg" /></td>
</tr>
</table>
</div> <div class="slchanpingCon01-r">
<p class="slchanpingCon01-p1"><a href="">金装智多多三文鱼营养面条5</a></p>
<p>售价 <span style="font-weight:bold;color:#777">¥18.80</span></p>
<p class="slchanpingCon01-links"><a href="">产品详情</a>  <a href="">在线订购</a></p>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>

  
<script type="text/javascript">
window.onload=function(){

var oUl=document.getElementById('slchanpingCon01');
var aLi=oUl.getElementsByTagName('li');
var len=aLi.length;

var w=aLi[0].offsetWidth;
var index=0;
var b=true;
var timer=null; function next(){
b?index++:index--;
(index==0 || index==len-1) && (b=!b);

startMove(-index*w);

}

setInterval(next,3200);
function doMove(iTarget){
var iSpeed=(iTarget-oUl.offsetLeft)/14;
iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);
oUl.offsetLeft == iTarget ? clearInterval(timer) : oUl.style.left = oUl.offsetLeft + iSpeed + "px";
};
function startMove(iTarget){
clearInterval(timer);
timer=setInterval(function(){
doMove(iTarget);
},30)
};
};
</script>
 </body>
</html>

解决方案 »

  1.   

    function next() {
        b ? index++ : index--; // b应该是一只全局变量,判断如果值为ture,index自增1;否则index自减1
        (index == 0 || index == len - 1) && (b = !b);  //如果index值为0或者index值等于len - 1,b取非,否则什么都不做
        startMove(-index * w); //这个不用解释了吧
    }//相当于
    function next() {
        if (b) index ++;
        else index --;
        if (index == 0 || index == len - 1) b = !b;
        startMove(-index * w);
    }昨天有个类似的问题,参考一下:
    http://topic.csdn.net/u/20110807/16/7cdc0913-0f41-42ae-8baf-1676c26c22c3.html
      

  2.   

    var b = true;
    b = !b;
    alert(b); //false
    b = !b;
    alert(b); //true
      

  3.   

    当然是给b赋值了,把b的非赋给b