简体   繁体   English

如何默认选择特定页面?

[英]How to get particular page selected by default?

I have a pagination as shown in here https://jsfiddle.net/solodev/yw7y4wez/ 我有一个分页,如https://jsfiddle.net/solodev/yw7y4wez/所示

I want to get some page selected or highlighted by default (suppose page 8) 我希望默认选择或突出显示某些页面(假设第8页)

I tried following code but it doesn't work 我试过跟随代码,但它不起作用

page = '@Model.CurrentPageIndex';
$('.page-active').removeClass('page-active');
$('#page' + page).addClass('page-active');

where '@Model.CurrentPageIndex' contains page no. 其中'@ Model.CurrentPageIndex'包含第页编号。 (eg 8) (例如8)

Try below: 试试以下:

var page = '@Model.CurrentPageIndex';
$('.page-active').removeClass('page-active');

$('ul.pagination li a.page-link').each(function(index) {
    if (Number($(this).html()) === Number(page)) {
     $(this).closest('li').addClass('page-active');
    }
});

Try following, 试试以下,

page = '@Model.CurrentPageIndex';
$('#pagination-demo').twbsPagination('show', page);

Pagination allows you to set the startpage. 分页允许您设置起始页。 You have it in your jsfiddle example. 你在jsfiddle例子中有它。

$('#pagination-demo').twbsPagination({
totalPages: 5,
// the current page that show on start
startPage: 2, //THIS IS THE LINE THAT CHANGES START PAGE

// maximum visible pages
visiblePages: 5,

initiateStartPageClick: true,

// template for pagination links
href: false,

// variable name in href template for page number
hrefVariable: '{{number}}',

// Text labels
first: 'First',
prev: 'Previous',
next: 'Next',
last: 'Last',

// carousel-style pagination
loop: false,

// callback function
onPageClick: function (event, page) {
    $('.page-active').removeClass('page-active');
  $('#page'+page).addClass('page-active');
},

// pagination Classes
paginationClass: 'pagination',
nextClass: 'next',
prevClass: 'prev',
lastClass: 'last',
firstClass: 'first',
pageClass: 'page',
activeClass: 'active',
disabledClass: 'disabled',

});

When you are using this plugin, it is probably be best to use its functions rather than add your own functionality on top. 当您使用此插件时,最好使用其功能,而不是在顶部添加您自己的功能。 This way, it ensures that other functions such as "previous", and "last" still works. 这样,它可以确保“previous”和“last”等其他功能仍然有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取页面刷新时的默认选定项目 - Get default selected item on page refresh 如何获取选定的文本范围并为特定的选定文本添加颜色 - how to get selected text range and add color to the particular selected text 如何:在名称上选择,以获取该特定所选记录的ID - How to : on name select get the id of that particular selected record 如何使用Jquery获取特定ID的所有选定下拉列表值 - How to get all selected dropdown values for a particular Id using Jquery 在jQuery中,如何获取使用复选框选择的表的特定行的值? - In jquery how to get the values of a particular row of a table that is selected using checkbox? 如何获取两个选定的月份日期之间的一周中的特定日期 - How to get the particular dates of a week between two selected month dates 在重定向页面上获取所选项目-如何? - get selected item on redirected page — how? Angular.js select:如何获取所选项目的位置并设置默认选择 - Angularjs select: How to get the position of the selected item and set default selection 如何在另一个div中以简单文本的形式获取下拉菜单中所选的默认值 - how to get the dropdown selected default values in another div as a simple text 如何获取html页面上特定部分的背景颜色 - How to GET background color of a particular portion on the html page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM