如何在HTML中创建AJAX分页?

时间:2021-11-21 14:30:35

my code:

$(document).ready(function(){
    $("#conteudo").click(function( e ){
        e.preventDefault();
        var href = $( this ).attr('href');
        $('#paginacao a').load(href +'#conteudo');
    });
});

<ul id="paginacao">
            <li><a href="index.html">1</a></li>
            <li><a href="pagina2.html">2</a></li>
</ul>

Is not working, what's missing? HELP!

不工作,缺少什么?帮帮我!

1 个解决方案

#1


0  

You've bound to the UL element itself. You should be binding to the links (A)

你已经绑定了UL元素本身。你应该绑定到链接(A)

$(document).ready(function(){
   $("#conteudo a").click(function( e ){
       e.preventDefault();
       var href = $( this ).attr('href');
       $('#paginacao a').load(href +'#conteudo');
   });
});

Also, this bit of code

还有,这段代码

       $('#paginacao a').load(href +'#conteudo');

Are you attempting to load the contents of the AJAX call into the link? Shouldn't you be loading it into a separate container?

您是否尝试将AJAX调用的内容加载到链接中?你不应该将它装入一个单独的容器吗?

#1


0  

You've bound to the UL element itself. You should be binding to the links (A)

你已经绑定了UL元素本身。你应该绑定到链接(A)

$(document).ready(function(){
   $("#conteudo a").click(function( e ){
       e.preventDefault();
       var href = $( this ).attr('href');
       $('#paginacao a').load(href +'#conteudo');
   });
});

Also, this bit of code

还有,这段代码

       $('#paginacao a').load(href +'#conteudo');

Are you attempting to load the contents of the AJAX call into the link? Shouldn't you be loading it into a separate container?

您是否尝试将AJAX调用的内容加载到链接中?你不应该将它装入一个单独的容器吗?