Jquery:模拟用户单击上一步按钮/链接

时间:2015-03-08 15:18:55

标签: jquery wordpress click

Hy Guys,

我正在使用以下代码执行的操作是通过模拟用户点击Previous -Next分页按钮,手动(通过用户点击)导航的分页表行转换为自动提前。

我使用以下setInterval函数通过模拟鼠标单击Next按钮“#tablepress-1_next”进入下一页,并且工作正常。

window.setInterval(function() 
    { 
        $('#tablepress-1_next').triggerHandler('click');
    }, 6000);

});

现在我想通过模拟用户点击“上一页”按钮来向后导航,但这对我来说有点太多了,因为我是jquery noob。 anybuddy可以帮助修改上面的功能,以便当所有行都向前推进或者可以从Page-1再次开始而不是向后向前导航时,它模拟单击“上一步”按钮(“#tablepress-1_prev”)。

Tablepress将“禁用”类添加到“上一页”按钮(如果它是Page-1)和“Next”按钮(如果它是最后一页)。

Tablepress是一个wordpress插件。

由于 问候, DKJ

1 个答案:

答案 0 :(得分:1)

如果有可用于此目的的API,我建议不要使用DOM事件来处理导航。 DataTables API提供了一些处理导航的功能,我添加了一个演示功能的jsfiddle。基本上这些代码行是处理自动分页所必需的:

// create the DataTable 
var table = $('#example').DataTable();
// retrieve the page information
var info = table.page.info();
// initialise the paging direction
var direction= 'asc';

// in case there are more than 1 pages of data, start pagination 
if (info.pages > 1) {
  // start cycling the pages now
  window.setInterval(function() {
    if (direction=='asc') {
      table.page( 'next' ).draw( false );
      // switch directions if last page of data shown
      if (table.page()+1 == info.pages) direction= 'desc';
    } else {
      table.page( 'previous' ).draw( false );
      // switch directions if the first page of data is shown
      if (table.page() == 1) direction= 'asc';   
    }
  }, 2000);
}

祝你好运,让我知道这是否适合您!

相关问题