- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个代码,可以为每 8 组数据创建一个分页,这是我的代码
<script>
function LoadAllData(){
google.script.run.withSuccessHandler(GenerateMainTable).getData();
}
function GenerateMainTable(data) {
var createcard = document.getElementById("maincontainer");
createcard.innerHTML += ''
for (var i = 1; i < data.length; i++) {
var imagelink = data[i][0],
brand = data[i][1],
prodcat = data[i][2],
prodcode = data[i][3],
prodname = data[i][4],
packaging = data[i][5],
srp = data[i][6] ,
des1 = data[i][7],
des2 = data[i][8],
des3 = data[i][9],
des4 = data[i][10],
des5 = data[i][11],
des6 = data[i][12];
if (data[i][0] === "") { break; }
createcard.innerHTML += '<div class="card">' +
'<div id="one">' +
'<img class = "tableformat" src="' + imagelink + '" alt="Product" height="94%" width="94%" align = "center">' +
'</div>' +
'<div id="two">'+
'<table width = "100%" height = "100%" class = "tableformat">' +
' <tbody>' +
' <tr class = "tableformat">' +
' <td class = "tableformat">Product Description</td>' +
' <td class = "tableformat">SRP</td>' +
' <td class = "tableformat">Packaging</td>' +
' </tr>' +
' <tr class = "tableformat">' +
' <td class = "tableformat">' + prodcode + '</td>' +
' <td class = "tableformat">' + srp + '</td>' +
' <td class = "tableformat">' + packaging + '</td>' +
' </tr>' +
' <tr class = "tableformat">' +
' <td colspan="3" class = "tableformat">'+ des1 +'</td>' +
' </tr>' +
' <tr class = "tableformat">' +
' <td colspan="3" class = "tableformat">'+ des2 +'</td>' +
' </tr>' +
' <tr class = "tableformat">' +
' <td colspan="3" class = "tableformat">'+ des3 +'</td>' +
' </tr>' +
' <tr class = "tableformat">' +
' <td colspan="3" class = "tableformat">'+ des4 +'</td>' +
' </tr>' +
' <tr class = "tableformat">' +
' <td colspan="3" class = "tableformat">'+ des5 +'</td>' +
' </tr>' +
' <tr class = "tableformat">' +
' <td colspan="3" class = "tableformat">'+ des6 +'</td>' +
' </tr>' +
' </tbody>' +
'</table>'
'</div>' +
'</div>';
}
createcard.innerHTML += '</div>';
pageSize = 8;
var pageCount = $(".card").length / pageSize;
for(var i = 0 ; i<pageCount;i++){
$("#pagin").append('<li><a href="#">'+(i+1)+'</a></li> ');
}
$("#pagin li").first().find("a").addClass("current")
showPage = function(page) {
$(".card").hide();
$(".card").each(function(n) {
if (n >= pageSize * (page - 1) && n < pageSize * page)
$(this).show();
});
}
showPage(1);
$("#pagin li a").click(function() {
$("#pagin li a").removeClass("current");
$(this).addClass("current");
showPage(parseInt($(this).text()))
});
}
</script>
请注意这部分代码,因为它是创建分页的代码。
pageSize = 8;
var pageCount = $(".card").length / pageSize;
for(var i = 0 ; i<pageCount;i++){
$("#pagin").append('<li><a href="#">'+(i+1)+'</a></li> ');
}
$("#pagin li").first().find("a").addClass("current")
showPage = function(page) {
$(".card").hide();
$(".card").each(function(n) {
if (n >= pageSize * (page - 1) && n < pageSize * page)
$(this).show();
});
}
showPage(1);
$("#pagin li a").click(function() {
$("#pagin li a").removeClass("current");
$(this).addClass("current");
showPage(parseInt($(this).text()))
});
}
我的问题是,只要我有数据,代码就会创建分页,而这正是我不想要的。所以我的目标是如何添加这样的东西?
**第一个 << 1 2 3 4 5 6 7 8 >> 最后一个*
** 请查看更新后的代码 **
<script>
function LoadAllData(){
google.script.run.withSuccessHandler(GenerateMainTable).getData();
}
function GenerateMainTable(data) {
var createcard = document.getElementById("maincontainer");
createcard.innerHTML += ''
for (var i = 1; i < data.length; i++) {
var imagelink = data[i][0],
brand = data[i][1],
prodcat = data[i][2],
prodcode = data[i][3],
prodname = data[i][4],
packaging = data[i][5],
srp = data[i][6] ,
des1 = data[i][7],
des2 = data[i][8],
des3 = data[i][9],
des4 = data[i][10],
des5 = data[i][11],
des6 = data[i][12];
if (data[i][0] === "") { break; }
createcard.innerHTML += '<div class="card">' +
'<div id="one">' +
'<img class = "tableformat" src="' + imagelink + '" alt="Product" height="94%" width="94%" align = "center">' +
'</div>' +
'<div id="two">'+
'<table width = "100%" height = "100%" class = "tableformat">' +
' <tbody>' +
' <tr class = "tableformat">' +
' <td class = "tableformat">Product Description</td>' +
' <td class = "tableformat">SRP</td>' +
' <td class = "tableformat">Packaging</td>' +
' </tr>' +
' <tr class = "tableformat">' +
' <td class = "tableformat">' + prodcode + '</td>' +
' <td class = "tableformat">' + srp + '</td>' +
' <td class = "tableformat">' + packaging + '</td>' +
' </tr>' +
' <tr class = "tableformat">' +
' <td colspan="3" class = "tableformat">'+ des1 +'</td>' +
' </tr>' +
' <tr class = "tableformat">' +
' <td colspan="3" class = "tableformat">'+ des2 +'</td>' +
' </tr>' +
' <tr class = "tableformat">' +
' <td colspan="3" class = "tableformat">'+ des3 +'</td>' +
' </tr>' +
' <tr class = "tableformat">' +
' <td colspan="3" class = "tableformat">'+ des4 +'</td>' +
' </tr>' +
' <tr class = "tableformat">' +
' <td colspan="3" class = "tableformat">'+ des5 +'</td>' +
' </tr>' +
' <tr class = "tableformat">' +
' <td colspan="3" class = "tableformat">'+ des6 +'</td>' +
' </tr>' +
' </tbody>' +
'</table>'
'</div>' +
'</div>';
}
createcard.innerHTML += '</div>';
var curPage;
curPage = 0;
var showPage = function(page) {
'use strict';
$(".card").hide();
$(".card").each(function(n) { if (n >= pageSize * (page - 1) && n < pageSize * page) $(this).show(); });
curPage = page;
};
//group Size
var groupSize;
groupSize = 8;
//Page size is equal to ( data.length - remainder ) divide by group size
// get an interger not float
//Using data.length not getting elements
//This will improve perfomance
//Remove this declaration Used for code hinting in dreamweaver
var data;
var pageSize;
pageSize = ( data.length - ( data.length % groupSize ) ) / groupSize;
var pagin = $("#pagin");
var addChild = function( name, callback, x ){
'use strict';
var clas = '';
if(x && x !== void(0 ) && x === 1 ){
clas = 'current';
}
//This Works
//pagin.append( '<li><a href="#" ' + clas +' >' + name + '</a></li>' );
//untested code
var html = $('<li><a href="#">' + name + '</a></li>' );
html.click( callback );
html.appendTo( pagin );
//return true;
void( callback );
};
//Add Previous Calls
addChild( 'Previous', function(){ 'use strict'; var i = curPage - 1; showPage(i); } );
addChild( '<<', function(){ 'use strict'; var i = curPage - 1; showPage(i); } );
//Loop through all Elements
for( var i = 0; i < pageSize; i++ ){
addChild( pageSize + 1 , showPage.bind( null, i ), i );
}
//Add Previous Calls
addChild( '>>', function(){ 'use strict'; var i = curPage + 1; showPage(i); } );
addChild( 'Next', function(){ 'use strict'; var i = curPage + 1; showPage(i); } );
}
</script>
这是输出
您可以使用此示例代码
<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="https://cssglobe.com/lab/easypaginate/js/easypaginate.js"></script>
<style>
.card {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
transition: 0.3s;
width: 49%;
height: 206px;
display:inline-block;
margin-left: 7px;
margin-bottom: 20px;
}
.card:hover {
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
}
div#one {
width: 30%;
height: 100%;
float: left;
}
div#two {
margin-left: 30%;
height: 100%;
}
* {
font-family: 'Lato', sans-serif;
font-size: 12px;
}
.tableformat{
border:1px solid #ddd;
border-collapse: collapse;
padding: 5px;
text-align:left;
}
.img{
display: block;
margin: auto;
}
body {
font-family: arial;
}
select {
border: 1px solid #d6d8db;
background-color: #ecedee;
text-transform: uppercase;
color: #47515c;
padding: 12px 30px 12px 10px;
width: 300px;
cursor: pointer;
margin-bottom: 10px;
}
select > option {
text-transform: uppercase;
padding: 5px 0px;
}
.customSelect {
border: 1px solid #d6d8db;
background-color: #ecedee;
text-transform: uppercase;
color: #47515c;
padding: 12px 10px 12px 10px;
margin-bottom: 10px;
}
.customSelect.changed {
background-color: #f0dea4;
}
.customSelectInner {
background:url(http://cdn1.iconfinder.com/data/icons/cc_mono_icon_set/blacks/16x16/br_down.png) no-repeat center right;
}
#pagin li {
display: inline-block;
margin: 1px;
}
.pagination a {
color: black;
padding: 8px 16px;
text-decoration: none;
transition: background-color .3s;
border: 1px solid #ddd;
}
.pagination a.active {
background-color: #4CAF50;
color: white;
border: 1px solid #4CAF50;
}
.pagination a:hover:not(.active) {background-color: #ddd;}
input[type=text] {
width: 300px;
height: 30px;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 12px;
background-color: white;
background-image: url('https://thumb.ibb.co/dWPwc5/searchicon.jpg');
background-position: 10px 3px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
}
</style>
</head>
<body onLoad = "GenerateMainTable()">
<input type="text" name="search" placeholder="Search..">
<br>
<div class="pagination" style=" margin: 0 auto;"><ul id="pagin"></ul></div>
<div id = "maincontainer" class = "maincontainer" width = "100%" >
</div>
<script>
function GenerateMainTable() {
var data = [
['dataid1', 'area1', 'cusname1', 'cic1', 'remarks1', 'status1', 'docdate1'],
['dataid2', 'area2', 'cusname2', 'cic2', 'remarks2', 'status2', 'docdate2']
]
var createcard = document.getElementById("maincontainer");
createcard.innerHTML += ''
for (var i = 1; i < data.length; i++) {
var imagelink = data[i][0],
brand = data[i][1],
prodcat = data[i][2],
prodcode = data[i][3],
prodname = data[i][4],
packaging = data[i][5],
srp = data[i][6] ,
des1 = data[i][7],
des2 = data[i][8],
des3 = data[i][9],
des4 = data[i][10],
des5 = data[i][11],
des6 = data[i][12];
if (data[i][0] === "") { break; }
createcard.innerHTML += '<div class="card">' +
'<div id="one">' +
'<img class = "tableformat" src="' + imagelink + '" alt="Product" height="94%" width="94%" align = "center">' +
'</div>' +
'<div id="two">'+
'<table width = "100%" height = "100%" class = "tableformat">' +
' <tbody>' +
' <tr class = "tableformat">' +
' <td class = "tableformat">Product Description</td>' +
' <td class = "tableformat">SRP</td>' +
' <td class = "tableformat">Packaging</td>' +
' </tr>' +
' <tr class = "tableformat">' +
' <td class = "tableformat">' + prodcode + '</td>' +
' <td class = "tableformat">' + srp + '</td>' +
' <td class = "tableformat">' + packaging + '</td>' +
' </tr>' +
' <tr class = "tableformat">' +
' <td colspan="3" class = "tableformat">'+ des1 +'</td>' +
' </tr>' +
' <tr class = "tableformat">' +
' <td colspan="3" class = "tableformat">'+ des2 +'</td>' +
' </tr>' +
' <tr class = "tableformat">' +
' <td colspan="3" class = "tableformat">'+ des3 +'</td>' +
' </tr>' +
' <tr class = "tableformat">' +
' <td colspan="3" class = "tableformat">'+ des4 +'</td>' +
' </tr>' +
' <tr class = "tableformat">' +
' <td colspan="3" class = "tableformat">'+ des5 +'</td>' +
' </tr>' +
' <tr class = "tableformat">' +
' <td colspan="3" class = "tableformat">'+ des6 +'</td>' +
' </tr>' +
' </tbody>' +
'</table>'
'</div>' +
'</div>';
}
createcard.innerHTML += '</div>';
pageSize = 8;
var pageCount = $(".card").length / pageSize;
for(var i = 0 ; i<pageCount;i++){
$("#pagin").append('<li><a href="#">'+(i+1)+'</a></li>');
}
$("#pagin li").first().find("a").addClass("current")
showPage = function(page) {
$(".card").hide();
$(".card").each(function(n) {
if (n >= pageSize * (page - 1) && n < pageSize * page)
$(this).show();
});
}
showPage(1);
$("#pagin li a").click(function() {
$("#pagin li a").removeClass("current");
$(this).addClass("current");
showPage(parseInt($(this).text()))
});
}
</script>
</body>
</html>
最佳答案
像这样,你能澄清一下你想要数字的部分吗?
**
// JavaScript Document
/*
Creating Prev Next and Proper Paging
paging
ul > li > a
overview
ul >
li > a > Previous
li > a > <<
( li > a > 1 )*
li > a > >>
li > a > Next
*/
var curPage;
curPage = 0;
var showPage = function(page) {
'use strict';
$(".card").hide();
$(".card").each(function(n) { if (n >= pageSize * (page - 1) && n < pageSize * page) $(this).show(); });
curPage = page;
};
//group Size
var groupSize;
groupSize = 8;
//Page size is equal to ( data.length - remainder ) divide by group size
// get an interger not float
//Using data.length not getting elements
//This will improve perfomance
//Remove this declaration Used for code hinting in dreamweaver
var data;
var pageSize;
pageSize = ( data.length - ( data.length % groupSize ) ) / groupSize;
var pagin = $("#pagin");
var addChild = function( name, callback, x ){
'use strict';
var clas = '';
if(x && x !== void(0 ) && x === 1 ){
clas = 'current';
}
//This Works
//pagin.append( '<li><a href="#" ' + clas +' >' + name + '</a></li>' );
//untested code
var html = $('<li><a href="#">' + name + '</a></li>' );
html.click( callback );
html.appendTo( pagin );
//return true;
void( callback );
};
//Add Previous Calls
addChild( 'Previous', function(){ 'use strict'; var i = curPage - 1; showPage(i); } );
addChild( '<<', function(){ 'use strict'; var i = curPage - 1; showPage(i); } );
//Loop through all Elements
for( var i = 0; i < pageSize; i++ ){
addChild( pageSize + 1 , showPage.bind( null, i ), i );
}
//Add Previous Calls
addChild( '>>', function(){ 'use strict'; var i = curPage + 1; showPage(i); } );
addChild( 'Next', function(){ 'use strict'; var i = curPage + 1; showPage(i); } );
**
关于javascript - 循环下分页包含 First,Prev (<<) Next (>>),Last,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45410102/
我查阅了整个 jQuery 文档,但没有找到任何内容:是否可以搜索当前元素之前具有特定类的元素?我以为这会起作用,但事实并非如此: $(this).prev('.bar'); http://jsfid
如何避免 .prev().prev().prev() 调用?有捷径吗? 最佳答案 您可以将 .prevAll 与 eq 或 :eq 结合使用,因为 prevAll 返回一组从最接近当前元素 [0] 的
目前我正在尝试使用 Node 运行一个非常基本的待办事项列表。设置 package.json 和 server.js 后,我运行了 npm start run,但出现了一个奇怪的错误。 更新:这是基本
我有一个名为 Scores 的表: mysql> select * from Scores; +------+-------+ | Id | Score | +------+-------+ |
我对这段代码有疑问: poss = [6,9,20] for n in range(6,66): if(n%6) == 0 or (n%9) == 0 or (n%20) == 0:
我正在阅读 React 钩子(Hook)的示例。我发现他们写 setCount(count + 1) 但我通常是这样写的 setCount(prev => prev + 1) 有什么区别吗?哪一个更好
如何使用 prev() 选择前一个元素?我希望当我点击icon 1时它会删除span。 html.erb # inside a loop -- notice the loop!. icon 1
我有这个 html 代码: 1 require 'yaml' 2 require 'set' 3 4 module ActiveRecord #:nodoc: 5
如何避免双重释放或损坏 (!prev) 我有这些结构: 空设备,始终有效 static struct mixer null_mixer = { .set_device = null_set_d
I get the following error when running a c program: * Error in `./final': double free or corruption
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: jquery find closest previous sibling with class 下面给出的代
我在一个文件中有这样的代码... $d = new db(); class db { function fetchform() { global $wpdb; $con
我想在点击事件中将类添加到最近的 p: http://jsfiddle.net/d7gFf/2/ 但这无法向 p 元素添加或删除类。点击事件有什么问题。 提前致谢 最佳答案 closest()搜索祖先
我在 jQuery 中使用 prev() 时遇到问题,它没有选择正确的元素。 我的HTML结构如下: ... ... “事件”部分是#contact。我想选择上一节,跳过
首先,我使用名为listrec的结构定义了节点。因此,每个节点包含3个部分:prev(用于存储前一个节点的地址),value(用于存储值)和next(用于存储下一个节点的地址)。 #include
我正在尝试删除以下代码的最后两个中断标记实例: Link stupid font tag Someth
代码: h4 inside anchor This is a sibling paragraph of that anchor which had h4 in it
鉴于这个简单的设置 I'm spoiled I'm spoiled 当我检测到对类“uncle”的点击时,我想获取最近的前一个“.parent”的同级。我应该可以做到 $(
当我使用 $('#btn').prev().text('new string'); 单击按钮时,我成功更改了按钮值但我不知道为什么应该使用 .prev() 根据http://api.jquery.co
我正在尝试使用 jQuery 获取输入值。在我的真实代码中,我有更多的输入和按钮,因此像: .middle() 这样的代码将不起作用!我需要从 btn 向上遍历。 HTML Help Alert
我是一名优秀的程序员,十分优秀!