Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

分页JS 模板 #43

Open
mishe opened this issue Dec 3, 2015 · 0 comments
Open

分页JS 模板 #43

mishe opened this issue Dec 3, 2015 · 0 comments

Comments

@mishe
Copy link
Owner

mishe commented Dec 3, 2015

分页模板(underscore)

<div class="pages">
<% if(countPage<5){
    for(var i=1;i<=countPage;i++){ %>
    <a href="javascript:;" data-id="<%=i%>" class="<%=curPage==i?'curPage':''%>"><%=i%></a>
<% }
}else{
    if(curPage<5){
        for (var i = 1; i <5; i++) { %>
        <a href="javascript:;" data-id="<%=i%>" class="<%=curPage==i?'curPage':''%>"><%=i%></a>
       <% } %>
        ...<a href="javascript:;" data-id="<%=countPage%>"><%=countPage%></a>
   <% }else if(curPage>4 && curPage<countPage-3){ %>
        <a href="javascript:;" data-id="1">1</a>...
        <% for (var i = curPage-2; i <= curPage+2; i++) { %>
        <a href="javascript:;" data-id="<%=i%>" class="<%=curPage==i?'curPage':''%>"><%=i%></a>
        <% } %>
        ...<a href="javascript:;" data-id="<%=countPage%>"><%=countPage%></a>
    <% }else{ %>
        <a href="javascript:;" data-id="1">1</a>...
        <% for (var i = countPage-4; i <= countPage; i++) { %>
        <a href="javascript:;" data-id="<%=i%>" class="<%=curPage==i?'curPage':''%>"><%=i%></a>
    <% }
    }
}
if(pageSize>0 && countPage>0){ %>
    每页显示 <select>
                <option value="10"<%=pageSize==10?' selected':''%>>10</option>
                <option value="20"<%=pageSize==20?' selected':''%>>20</option>
                <option value="40"<%=pageSize==40?' selected':''%>>40</option>
                <option value="100"<%=pageSize==100?' selected':''%>>100</option>
            </select>

    跳转到<input type="text" value="<%=curPage%>">
    <% }%>
</div>

需要传入参数:

pages.countPage=Math.floor(len/pageSize)+(len%pageSize>0?1:0);
                pages.curPage=parseInt(page);
                pages.pageSize=0;
                $('#pages').html(_.template(pageTemplate,pages));
events:{
                'click .pages a':'pages',
                'change .pages select':'changePageSize',
                'blur .pages input':'gotoInputPage',
            },
            pages:function(event){
                var self=$(event.currentTarget);
                this.render(self.attr('data-id'));
            },
            changePageSize:function(event){
                var self=$(event.currentTarget);
                this.pageSize=self.val();
                this.render();
            },
            gotoInputPage:function(event){
                var self=$(event.currentTarget);
                this.render(self.val());
            }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant