【发布时间】: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">$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">$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