通过jquery实现页码的加减,到达最小或最大后不再变化。
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script src="../js/jquery-1.12.4.js" type="text/javascript"></script>
<script>
$(function () {
$("button").click(function () {
let n = $(this).text();
// console.log(n);
if (n == "《") {
if ($("button:eq(1)").text() == "1" && $("button:eq(5)").text() != "100") {
//这个100可以转化为变量从而控制页数
} else {
$("button:gt(0):lt(5)").each(function () {
let a = $(this).text();
// console.log(a);
let b =Number(a)-1;
// console.log(b);
$(this).text(b);
// console.log($(this).text());
})
}
}
if (n == "》") {
if ($("button:eq(1)").text() != "1" && $("button:eq(5)").text() == "100") {
} else {
$("button:gt(0):lt(5)").each(function () {
let a = $(this).text();
// console.log(a);
let b =Number(a)+1;
// console.log(b);
$(this).text(b);
// console.log($(this).text());
})
}
}
})
})
</script>
<button>《</button>
<button>1</button>
<button>2</button>
<button>3</button>
<button>4</button>
<button>5</button>
<button>》</button>
</body>
</html>
运行结果:
点击最右边按钮:
注:需下载jQuery文件或者直接使用网上链接jQuery文件,才可运行文件