【问题标题】:My js pagination code is not working, completely lost as to what is causing it我的 js 分页代码不起作用,完全不知道是什么原因造成的
【发布时间】:2015-03-30 05:58:50
【问题描述】:

我有一个分页设置,我以前使用过很多次...非常适合列表和简单的段落,但我无法让它与更复杂的 html 代码一起使用,如下所列。出于某种原因,js 拒绝将以下代码转换为 set 对象以进行分页。

<div class="properties-content">
    <div id="paging_container8" class="container">
        <div class="storybody">
            <p>
                <!---------- Property Start ---------->
                <article class="hentry">
                    <div class="property-featured"> <a class="content-thumb" href="property-details.html"> <img src="images/property/property3.jpg" alt=""> </a> <span class="property-label last">Last one left</span> <span class="property-category"><a href="#">Single Family Home</a> </span> </div>
                    <div class="property-wrap">
                        <h2 class="property-title"> <a href="property-details.html" title="Single Family Residential, NJ">Single Family Residential, NJ</a> </h2>
                        <div class="property-excerpt">
                            <p>Classic 60's ranch living. House has hardwood floors and hard coat plaster walls and ceilings...</p>
                            <p class="property-fullwidth-excerpt">Classic 60's ranch living. House has hardwood floors and hard coat plaster walls and ceilings in good condition. Intimate backyard for private gatherings. Full basement...</p>
                        </div>

                        <div class="property-summary">
                            <div class="property-detail">
                                <div class="size"> <span>1118 sqft</span> </div>
                                <div class="bathrooms"> <span>2</span> </div>
                                <div class="bedrooms"> <span>3</span> </div>
                            </div>

                            <div class="property-info">
                                <div class="property-price"> <span> <span class="amount">&#36;299,000</span> </span> </div>
                                <div class="property-action"> <a href="property-details.html">More Details</a> </div>
                            </div>

                            <div class="property-info property-fullwidth-info">
                                <div class="property-price"> <span><span class="amount">&#36;299,000</span> </span> </div>
                                <div class="size"><span>1118 sqft</span> </div>
                                <div class="bathrooms"><span>2</span> </div>
                                <div class="bedrooms"><span>3</span> </div>
                            </div>
                        </div>
                    </div>

                    <div class="property-action property-fullwidth-action"> <a href="property-details.html">More Details</a> </div>
                </article>
                <!---------- Property End ----------> 
                <!---------- Property End ---------->
            </p>

            <div class="page_navigation"></div>

由于我的 css 是这样的,我需要显示上述代码中的 2 个,可能是 25 个。这是我正在使用的 javascript:

<script>
var str= $(".storybody").html();
var substr=str.split( "<!--pagebreak-->" );
var txt="<ul class='storycontent'><li>";
var x=0;
for (x in substr)
  {
    if(x==0){
        txt=txt+substr[x];
    }
    else{
          txt=txt+"</li><li>"+substr[x];
    }
  }
var paginated=txt+"</li></ul>";
$('div.storybody').replaceWith(paginated);

$(document).ready(function(){
                $('#paging_container8').pajinate({
                    num_page_links_to_display : 2,
                    items_per_page : 1 ,
                    item_container_id : '.storycontent'
                });
            });
​</script>

这里是 jsfiddle:http://jsfiddle.net/moLwmyyr/1/

【问题讨论】:

  • 离题:嵌套段落不是有效的 HTML。
  • 有效!= 有效。您应该关心代码的质量。
  • 一个简单的解决方法是将外部的p 标记更改为div 标记并重新应用维护布局所需的任何CSS。
  • 哦,我已经做到了。我有外部

    标签,因为这是编写 js 代码以接受的方式,并且无法使用

    标签。现在我已经修复了它,我将它设置为
    而不是

标签: javascript jquery pagination


【解决方案1】:

我想通了!

以下 js 以及小提琴中的 js 在我的问题中使用我的 html 代码。原来的js只适用于简单的列表、表格和段落,这里列出的js将适用于嵌套的html代码。

(function($){

$(document).ready(function(){

    $(".pagination").customPaginate({

        itemsToPaginate : ".post"

    });

    });

})(jQuery)

http://jsfiddle.net/moLwmyyr/2/

与我的网站和 css 完美搭配。希望这对其他人有帮助。

【讨论】:

    猜你喜欢
    • 2018-04-12
    • 2020-09-19
    • 2014-01-17
    • 2020-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多