[英]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.