phpcms
是一个基于 PHP 的内容管理系统(CMS),它提供了丰富的功能来帮助用户管理和发布网站内容。二级列表分页是指在一个列表页面中嵌套另一个列表页面,并且每个列表都可以进行分页显示。
二级列表分页常用于以下场景:
以下是一个简单的 phpcms
二级列表分页的示例代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>二级列表分页示例</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<div id="main-list">
<!-- 主列表 -->
</div>
<div id="sub-list">
<!-- 子列表 -->
</div>
<script>
$(document).ready(function() {
// 加载主列表
$.ajax({
url: 'get_main_list.php',
type: 'GET',
success: function(data) {
$('#main-list').html(data);
}
});
// 点击主列表项加载子列表
$('#main-list').on('click', '.main-item', function() {
var categoryId = $(this).data('id');
$.ajax({
url: 'get_sub_list.php',
type: 'GET',
data: { category_id: categoryId },
success: function(data) {
$('#sub-list').html(data);
}
});
});
});
</script>
</body>
</html>
get_main_list.php
<?php
// 假设这是从数据库获取主列表数据的代码
$mainList = [
['id' => 1, 'name' => '分类1'],
['id' => 2, 'name' => '分类2'],
// ...
];
foreach ($mainList as $item) {
echo '<div class="main-item" data-id="' . $item['id'] . '">' . $item['name'] . '</div>';
}
?>
get_sub_list.php
<?php
// 假设这是从数据库获取子列表数据的代码
$categoryId = $_GET['category_id'];
$subList = [
['id' => 1, 'title' => '子项1'],
['id' => 2, 'title' => '子项2'],
// ...
];
foreach ($subList as $item) {
echo '<div class="sub-item">' . $item['title'] . '</div>';
}
?>
希望以上信息对你有所帮助!
领取专属 10元无门槛券
手把手带您无忧上云