当前位置:编程学习 > JS >>

jQuery+FCK编辑器+PHP实现文章分页代码

这款jquery+fck编辑器+php教程实现文章分页代码是一款在新闻开发中会常用到的,我们经常把太长的文章要分页显示,这样对搜索引擎与用户都好。

在fck中插入分页符如下图

分页代码

 

function pagebreak($content)
{
$content = $content;
$pattern = "/<div style="page-break-after: always"><span style="display: none"> </span></div>/";
$strsplit = preg_split($pattern, $content, -1, preg_split_no_empty);
$count = count($strsplit);
$outstr = "";
$i = 1;

if ($count > 1 ) {
$outstr = "<div id='page_break'>";
foreach($strsplit as $value) {
if ($i <= 1) {
$outstr .= "<div id='page_$i'>$value</div>";
} else {
$outstr .= "<div id='page_$i' class='collaps教程e'>$value</div>";
}
$i++;
}

$outstr .= "<div class='num'>";
for ($i = 1; $i <= $count; $i++) {
$outstr .= "<li>$i</li>";
}
$outstr .= "</div></div>";
return $outstr;
} else {
return $content;
}
}

jquery实现代码

 

$(document).ready(function(){
$('#page_break .num li:first').addclass('on');

$('#page_break .num li').click(function(){
//隐藏所有页内容
$("#page_break div[id^='page_']").hide();

//显示当前页内容。
if ($(this).hasclass('on')) {
$('#page_break #page_' + $(this).text()).show();
} else {
$('#page_break .num li').removeclass('on');
$(this).addclass('on');
$('#page_break #page_' + $(this).text()).fadein('normal');
}
});
});

css教程控制分页样式

 

#page_break {

}
#page_break .collapse {
display: none;
}
#page_break .num {
padding: 10px 0;
text-align: center;
}
#page_break .num li{
display: inline;
margin: 0 2px;
padding: 3px 5px;
border: 1px solid #ff7300;
background-color: #fff;

color: #ff7300;
text-align: center;
cursor: pointer;
font-family: arial;
font-size: 12px;
overflow: hidden;
}
#page_break .num li.on{
background-color: #ff7300;

color: #fff;
font-weight: bold;
}

分页效果

补充:网页制作,jquery 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,