开发者

jQuery Cycle Plugin - Change Pager Anchors to Weekdays

开发者 https://www.devze.com 2022-12-17 01:38 出处:网络
I want to create a menu that sorts by days. Everything works except the pager won\'t output weekdays. 开发者_高级运维My code is as follows:

I want to create a menu that sorts by days. Everything works except the pager won't output weekdays. 开发者_高级运维My code is as follows:

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

It still defaults to numbers, however. Can someone point me in the right direction?


You have three errors. First, don't use document.write inline, second, you are nesting an extra options element. The whole thing passed to the cycle call are the options. Third, both idx and your array are zero indexed, so no need for the + 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>';
      }
  });
0

精彩评论

暂无评论...
验证码 换一张
取 消