简体   繁体   English

Jquery UI的Tab内容中的分页

[英]Pagination in Tab Content of Jquery UI

I am making a page with Jquery UI TABS. 我正在使用Jquery UI TABS创建一个页面。 In one of tabs I want to make pagination for comments. 在其中一个标签中,我想对评论进行分页。 I want such thing. 我想要这样的东西。 When user clicks on the number of the page, the data of the page , which is linked will load via ajax in the tab. 当用户单击页面编号时,链接的页面数据将通过选项卡中的ajax加载。

Here is my code 这是我的代码

<script type="text/javascript">
 $(function() {
  $("#tabs").tabs();
 });



 $('#demo').tabs({
    load: function(event, ui) {
        $('a', ui.panel).click(function() {
            $(ui.panel).load(this.href);
            return false;
        });
    }
});




 </script>

How can I change this , so that any link inside the content with lets say with id "pagination" 如何更改此内容,以便内容中的任何链接都可以用id“pagination”来表示

<a href="/coments?page=12&user_id=12" id="pagination">12</a>

?? ?? Thanks beforehand 先谢谢

I tried recently like this even  and no luck. 

This is from http://www.bannerite.com/jquerytest/index2.php 这是来自http://www.bannerite.com/jquerytest/index2.php

Here it work 在这里工作

<script type="text/javascript">
    $(function() {          
        $("#tabs").tabs();
        var hijax = function(panel){
            $('a', panel).click(function() {            
                /**makes children 'a' on panel load via ajax, hence hijax*/
                $(panel).load(this.href, null, function(){
                    /**recursively apply the hijax to newly loaded panels*/
                    hijax(panel);                  
                });

                /**prevents propagation of click to document*/
                return false;
            });

            $('form', panel).css({background: 'yellow'}).ajaxForm({
                target: panel,
            });    
        };

        $('#demo ul').tabs({
            /**initialize the tabs hijax pattern*/
            load: function(tab, panel) {
                hijax(panel);
            }
        }); 
    });
</script>

HEre are the HTML part as Karl gived , but no succes. 是Karl给出的HTML部分,但没有成功。 When clicking on Test link its going to another page........ When clicking on 当点击Test链接时,它会转到另一个页面........点击时

I wanted to post HTML here but because of users with less reputation <10 cant give HTML with links I have posted it here 我想在这里发布HTML,但由于信誉较少的用户<10,不能给HTML链接我在这里发布

http://gevork.ru/2009/12/31/jquery-ui-tab-and-pagination-html/#more-58

One reason it might not work is that #demo isn't tabified within the ready event and instead right away. 它可能不起作用的一个原因是#demo在准备事件中没有被制表,而是立即。 As long as a scripts-at-the-bottom approach is not used this call needs to be moved into the anonymous function which is passed into $. 只要不使用底层脚本方法,就需要将此调用移动到传递给$的匿名函数中。

$(function() {    
    $('#tabs').tabs({
        load: function(event, ui) {
            $('a', ui.panel).click(function() {
                $(ui.panel).load(this.href);
                return false;
            });
        }
    });
});

Apart from that - without knowing about the actual HTML - I cannot tell if there's something else wrong. 除此之外 - 不知道实际的HTML - 我无法分辨是否有其他错误。

'any link with id "pagination"' sounds as if there were more than one. '任何带有id“pagination”的链接听起来好像有多个。 In that case: An id has to be unique so it should be changed to a class here. 在这种情况下:一个id必须是唯一的,所以它应该在这里改为一个类。

I think you have your code wrong where you have panel should be ui.panel. 我认为你的代码错误,你的面板应该是ui.panel。 This worked for me. 这对我有用。

<script type="text/javascript">
    $(function() {
        var hijax = function(panel) {
            $('a.pagination', panel).click(function(){
                $(panel).load(this.href, {}, function() {
                    hijax(this);
                });
                return false;
            });
        };
        $("#tabs").tabs({
            ajaxOptions: {
                error: function(xhr, status, index, anchor) {
                    $(anchor.hash).html("Couldn't load this tab.");
                },
            },
            load: function(event, ui) {
                hijax(ui.panel);

            }
        });
    });
</script>

I have wrote a plugin to do Hijax which seems migth help you. 我写了一个插件来做Hijax,似乎migth帮助你。 You would use instead of the Tabs plugin, so you might have to setup the tabs to show properly in css (I'm not familiar with the tabs plugin). 您可以使用而不是Tabs插件,因此您可能必须设置选项卡以在css中正确显示(我不熟悉选项卡插件)。

You can download, see the docs and an example: www.yarontadmor.co.cc/hijax.php 您可以下载,查看文档和示例: www.yarontadmor.co.cc/hijax.php

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM