jQuery循环插件 - 将寻呼机锚定更改为工作日

时间:2010-01-16 03:42:16

标签: jquery cycle

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

 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>';
        }
    }
});

但它仍默认为数字。有人能指出我正确的方向吗?

1 个答案:

答案 0 :(得分: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>';
      }
  });