开发者

binding functions and defining arguments for it

开发者 https://www.devze.com 2023-02-08 08:58 出处:网络
I\'m trying to do a jQuery search page with pagingation and want the pagination to look like this:开发者_Go百科 Prev 1 2 3 4 Next

I'm trying to do a jQuery search page with pagingation and want the pagination to look like this:开发者_Go百科 Prev 1 2 3 4 Next

The problem is that I need to add links to the numeric pages and bind them to a function that redo the search with the numeric values used for offset. This means that I need to pass a different numeric value as argument for each function that I'm binding to each link. Since I'm bad at jQuery and javascript, I have no idea how to do this. Could anyone point me in the right direction. Really need help here. Have tried to do this for several hours now.

I've tried to do the bind. But I belevie that there is something wrong with how I'm binind and then adding the link. This is what I'm trying to do at the moment: (NextPage is a function that performs the search).

  var a = '<a class="livesearch_next" href="javascript:void(0);" title="Next 5 Results">Next</a>';
  for( var i = 0; i < 5; i++)
  {
    var tmp = a;
    tmp.bind( 'click', { next: p, index: i}, function( event)
    {
      NextPage( event.data.next, event.data.index * 5);
    });

    $( ".paging").append( '<li>').append( a).append( '</li>');    
  }

Really hope someone could help me with this...


Your "bind" is working on a string (variable "tmp"), when you really want to be binding on an HTML element wrapped as a jQuery object. For that, you first need a jQuery object representing your hyperlink. Then, you need to do the bind on that jQuery object. Finally, append that jQuery object to the DOM element where you want the hyperlink to go.

0

精彩评论

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