3

我想创建一个按天排序的菜单。一切正常,除了寻呼机不会输出工作日。我的代码如下:

 var days = new Array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday" ); 
$('#main') 
.before('<div id="nav">') 
.cycle({ 
    fx:     'toss', 
    timeout: 0, 
    pager:  '#nav',
    options:    {
        pagerAnchorBuilder: function(i,el) {
            return '<a href="#">'+document.write(days[i+1])+'</a>';
        }
    }
});

但是,它仍然默认为数字。有人可以指出我正确的方向吗?

4

1 回答 1

3

你有三个错误。首先,不要使用document.write内联,其次,您正在嵌套一个额外的options元素。传递给cycle调用的全部内容是选项。第三,idx你的数组和你的数组都是零索引的,所以不需要+ 1

var days = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]; 
$('#main') 
  .before('<div id="nav">') 
  .cycle({ 
      fx:     'toss', 
      timeout: 0, 
      pager:  '#nav',
      pagerAnchorBuilder: function(i,el) {
          return '<a href="#">'+days[i]+'</a>';
      }
  });
于 2010-01-16T03:50:30.393 回答