if (!book.turn('hasPage', page)) { var element = $('<div />', {'class': 'own-size', css: {width: 460, height: 582} }). html('<div class="loader"></div>'); if (book.turn('addPage', element, page)) { loadPage(page); } }
时间: 2023-12-25 17:03:34 浏览: 48
这段代码是一个条件语句,用于检查指定页码的页面是否存在于书本对象中。如果该页面不存在,则执行一系列操作来添加并加载该页面。
以下是代码的功能解释:
1. `if (!book.turn('hasPage', page))` 判断书本对象 `book` 中是否存在指定页码 `page` 的页面。如果该页面不存在,则执行接下来的代码块。
2. 创建一个 `<div>` 元素,并设置其类名为 `'own-size'`。同时,使用 CSS 属性设置该元素的宽度为 460 像素,高度为 582 像素。
3. 在 `<div>` 元素中插入一个具有类名 `'loader'` 的子元素,用于显示加载动画。
4. 使用 `book.turn('addPage', element, page)` 方法将创建的 `<div>` 元素作为新页面添加到书本对象中的指定页码位置。如果添加成功,则执行接下来的代码块。
5. 调用 `loadPage(page)` 函数来加载指定页码的内容。
整体而言,这段代码的作用是检查指定页码的页面是否存在于书本对象中。如果不存在,则创建一个带有加载动画的 `<div>` 元素,并将其作为新页面添加到指定页码位置,并加载该页面的内容。这样可以确保在需要时动态地添加和加载页面。
相关问题
function addPage(page, book) { var id, pages = book.turn('pages'); if (!book.turn('hasPage', page)) { var element = $('<div />', {'class': 'own-size', css: {width: 460, height: 582} }). html('<div class="loader"></div>'); if (book.turn('addPage', element, page)) { loadPage(page); } } }
这段代码定义了一个名为`addPage`的函数,用于向书(`book`)中添加页面。该函数接受两个参数,`page`表示要添加的页面的页码,`book`表示书的元素。
首先,在函数内部声明了变量`id`和`pages`,其中`pages`是通过调用`book.turn('pages')`方法获取当前书籍的总页数。
接下来,使用条件判断`!book.turn('hasPage', page)`来检查是否已经存在指定页码的页面。如果不存在,则执行以下操作:
1. 创建一个`div`元素,并添加一个名为`own-size`的类。通过`css`属性设置该元素的宽度为460,高度为582。
2. 在该元素中插入一个具有名为`loader`的子元素,用于显示加载状态。
然后,通过调用`book.turn('addPage', element, page)`方法将创建的页面元素添加到书中的指定页码位置。如果添加页面成功,则调用`loadPage(page)`方法加载该页面的内容。
这段代码的作用是向书中添加页面,并在需要时加载页面内容。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>图书商城-图书列表</title> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <link rel="stylesheet" href="/BookShopSystem_war/layui/css/layui.css"> <link rel="stylesheet" href="/BookShopSystem_war/static/css/index.css"> <script src="https://cdn.bootcss.com/vue/2.5.16/vue.min.js"></script> <script src="https://unpkg.com/axios/dist/axios.min.js"></script> </head> <body> <div id="app"> <div class="layui-container"> <div class="hot-sell" v-if="bookAll.length > 0"> <div class="layui-row layui-col-space20"> <table> <tr> <td v-for="(bk,index) in currentBookAll" :key="index" class="layui-col-xs2" style="margin-left: 30px"> <a :href="'detail?id='+bk.bookId" class="text"> <div><img :src="'/BookShopSystem_war/' + bk.image1"></div> <p>{{bk.bookName}}</p> <p class="price">¥{{bk.bookPrice}}</p> </a> </td> </tr> </table> </div> </div> </div> <div id="houseList"></div> </div> <!-- 引入尾部footer.html --> <iframe src="footer.html" frameborder="0" scrolling="no" width="100%" height="245px"></iframe> </div> <script src="/BookShopSystem_war/layui/layui.js"></script>这是完整的html代码,请结合你给出的分页功能整合出完整的代码
好的,以下是结合分页功能的完整代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>图书商城-图书列表</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="/BookShopSystem_war/layui/css/layui.css">
<link rel="stylesheet" href="/BookShopSystem_war/static/css/index.css">
<script src="https://cdn.bootcss.com/vue/2.5.16/vue.min.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<div id="app">
<div class="layui-container">
<div class="hot-sell" v-if="bookAll.length > 0">
<div class="layui-row layui-col-space20">
<table>
<tr>
<td v-for="(bk,index) in currentBookAll" :key="index" class="layui-col-xs2" style="margin-left: 30px">
<a :href="'detail?id='+bk.bookId" class="text">
<div><img :src="'/BookShopSystem_war/' + bk.image1"></div>
<p>{{bk.bookName}}</p>
<p class="price">¥{{bk.bookPrice}}</p>
</a>
</td>
</tr>
</table>
</div>
</div>
<div class="layui-row">
<div class="layui-col-md12">
<div id="pagination"></div>
</div>
</div>
</div>
<div id="houseList"></div>
<!-- 引入尾部footer.html -->
<iframe src="footer.html" frameborder="0" scrolling="no" width="100%" height="245px"></iframe>
</div>
<script src="/BookShopSystem_war/layui/layui.js"></script>
<script>
layui.use('laypage', function(){
var laypage = layui.laypage;
var vm = new Vue({
el: '#app',
data: {
bookAll: [],
current: 1,
totalPage: 1,
currentBookAll: []
},
mounted: function() {
var _this = this;
axios.get('/BookShopSystem_war/book/all')
.then(function(response) {
_this.bookAll = response.data;
_this.totalPage = Math.ceil(_this.bookAll.length / 10);
_this.currentBookAll = _this.bookAll.slice(0, 10);
laypage.render({
elem: 'pagination',
count: _this.bookAll.length,
curr: _this.current,
limit: 10,
layout: ['prev', 'page', 'next', 'skip'],
jump: function(obj, first){
if(!first){
_this.currentBookAll = _this.bookAll.slice((obj.curr-1)*obj.limit, obj.curr*obj.limit);
}
}
});
})
.catch(function(error) {
console.log(error);
});
}
});
});
</script>
</body>
</html>
注意:这里的分页功能使用了 layui 的 laypage 组件,需要在页面中引入 layui.js 和 layui.css,并且需要在 Vue 的 mounted 钩子函数中调用 laypage.render() 方法来渲染分页组件。同时,需要注意在分页回调函数中更新当前显示的数据。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
图书管理 <label for="id"> 编号: </label> <input type="text" id="id" v-model='id' :disabled="flag"> <label for="name"> 名称: </label> <input type="text" id="name" v-model='name'> <button @click='handle'>提交</button> 编号 名称 时间 操作 {{item.id}} {{item.name}} {{item.date}} 修改 | 删除 用vue实现界面想要的图书信息修改,点击修改按钮后将编号传入编号输入栏并禁用,在图书名称输入栏进行名字的修改
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
{{ data.bookName }} {{ data.bookAuthor }} {{ data.bookPublish }} ¥{{ data.price }} 减 <input type="text" :value="data.num" readonly class="cOnt"> 加 ¥{{data.total}} 删除 new Vue({ el: '#app', data: { userId: '', list: [] // list: [ // {userId:null,bookName:"图书1",image1:"/BookShopSystem_war/cart/xzwxz.png",price:50,num:2}, // {userId:null,bookName:"图书2",image1:"/BookShopSystem_war/cart/xzwxz.png",price:50,num:1}, // {userId:null,bookName:"图书3",image1:"/BookShopSystem_war/cart/xzwxz.png",price:50,num:2} // ] }, //选择或不选择一项 $(".xzWxz").click(function () { if ($(this).hasClass("on")) { $(this).removeClass("on"); } else { $(this).addClass("on"); } var ty = $(".xzWxz.on").length; $(".sXd1").find("font").html(ty); if (ty == es) { $(".ifAll").addClass("on"); } else { $(".ifAll").removeClass("on"); } jsZj(); }); 当我使用未被注释的list,
该代码点击后没有变化,而我使用注释的静态list数组,该代码点击有变化,为什么,未注释的list是能获取到数据并遍历了出来,如何解决
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)