[英]if I am on the last page right navigation arrow should be invisible
I have news list in which new news is adding dynamically by appending 'li' to 'ul'.Its almost worked but the issue is all function are working on ONCLICK so when I go last news list page the right navigation is visible and when I click on that its get hide. 我有一个新闻列表,其中通过将'li'附加到'ul'来动态添加新新闻。它几乎起作用,但是问题是所有功能都在ONCLICK上起作用,所以当我转到上一个新闻列表页面时,可以看到正确的导航,当我单击它隐藏。
So I want if I am on the last page right navigation arrow should be invisible. 所以我想如果我在最后一页上,右导航箭头应该是不可见的。
This css to hide navigation arrows. 此CSS隐藏导航箭头。
.iconWrap.left,.hide-right{display: none;} .iconWrap.left-nav {display: block;}
This is navigation arrows structure: 这是导航箭头结构:
<div class="iconWrap left"><a onclick="leftarrow()" id="leftNav"></a></div>
<div class="iconWrap right"><a onclick="rightarrow()" id="rightNav"></a></div>
This is UL structure where li get append: 这是li获得附加的UL结构:
<ul id="news-list">----- Here all li adds dynamically----</ul>
this is the function to calculate records per page, total records: 这是计算每页记录总数的功能:
function NewsList(page, num_Per_Page){
$("#news-list").html("");
var start = parseInt(num_Per_Page) * parseInt(page);
var end = start + parseInt(num_Per_Page);
if(current_Page > 0){
$(".iconWrap.left").addClass("left-nav");
} else {
$(".iconWrap.left").removeClass("left-nav");
}
for(var z=start; z<end; z++){
if(news[z] == undefined) continue;
$("#news-list").append('<li><a href="#">--li data here--</a></li>');
}
}
below functions calling for navigation arrows: 下面的功能需要导航箭头:
function leftarrow(){
if(current_Page > 0){
current_Page--;
populateNewsList(current_Page, num_Records_PerPage);
}
}
function rightarrow() {
if((current_Page + 1) != (Math.ceil(<?=count($this->news)?>/num_Records_PerPage))){
current_Page++;
populateNewsList(current_Page, num_Records_PerPage);
} else {
$(".iconWrap.right").addClass("hide-right");
}
}
You could make it work even when function is executed onclick 即使在onclick上执行函数,也可以使其工作
Create a global variable that keeps count of total number of pages: 创建一个全局变量,以保留总页数:
var totalPages = Math.ceil(<?=count($this->news)?>/num_Records_PerPage))
You should make the logic of user interface different from the rest of the code. 您应该使用户界面的逻辑与其余代码不同。 Call the function after every time 'arrows' are clicked.
每次单击“箭头”后调用该函数。
function showArrows() {
if (currentPage > 1)
$(".iconWrap.left").addClass("left-nav");
else
$(".iconWrap.left").removeClass("left-nav");
if (currentPage >= totalPages)
$(".iconWrap.right").addClass("hide-right");
else
$(".iconWrap.right").removeClass("hide-right");
}
function NewsList(page, num_Per_Page){
$("#news-list").html("");
var start = parseInt(num_Per_Page) * parseInt(page);
var end = start + parseInt(num_Per_Page);
for(var z=start; z<end; z++){
if(news[z] == undefined) continue;
$("#news-list").append('<li><a href="#">--li data here--</a></li>');
}
}
function leftarrow(){
if(current_Page > 0){
current_Page--;
populateNewsList(current_Page, num_Records_PerPage);
}
showArrows();
}
function rightarrow() {
if((current_Page + 1) != totalPages){
current_Page++;
populateNewsList(current_Page, num_Records_PerPage);
}
showArrows(); // Call it every time arrows are clicked
}
You could also call showArrows()
when the documents completes loading to set initial value 当文档完成加载以设置初始值时,您也可以调用
showArrows()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.