当前位置:网站首页>Click event
Click event
2022-06-26 03:22:00 【Small vegetable bird yard live】
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>DOM</title>
<style>
*{
padding: 0;
margin: 0;
}
li{
list-style: none;
}
.header{
width: 1200px;
height: 50px;
margin: 0 auto;
border: 1px solid #ccc;
}
.header button{
float: left;
width: 100px;
height: 50px;
}
#nav{
width: 1000px;
height: 50px;
float: left;
}
#nav li{
width: 100px;
height: 50px;
text-align: center;
line-height: 50px;
float: left;
cursor: pointer;
}
.box{
width: 1200px;
height: 500px;
margin: 0 auto;
border: 1px solid red;
}
</style>
</head>
<body>
<div class="header">
<button id="prev"><</button>
<ul id="nav">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<button id="next">></button>
</div>
<div id="box" class="box">
<p></p>
<p></p>
<p></p>
</div>
<script src="data.js"></script>
<script>
// 1、 Get related elements
var prev = get('prev'),
lis = get('nav').children,
next = get('next'),
ps = get('box').children,
page = 0;
// 2、 The beginning is li Before rendering 10 A name
for(var i=0;i<10;i++){
lis[i].index = i;
lis[i].innerHTML = data[i].name;
// 3、 For each li Bind click event
lis[i].onclick = function(){
ps[0].innerHTML = data[page+this.index].name;
ps[1].innerHTML = data[page+this.index].age;
ps[2].innerHTML = data[page+this.index].xuehao;
}
}
// 4、 To the left and right button Bind click event
// Right arrow event
next.onclick = function(){
// the number of pages +10
page += 10;
if(page>data.length){
page -= 10;
return;
}
if(page===parseInt(data.length/10)*10){
for(var i=0;i<data.length%10;i++){
lis[i].innerHTML = data[i+page].name;
}
for(var i=data.length%10;i<10;i++){
lis[i].innerHTML = '';
}
}else{
// ten li The contents of the page become the contents of the current page
for(var i=0;i<10;i++){
lis[i].innerHTML = data[i+page].name;
}
}
// box The content in is that of the first person on the current page
ps[0].innerHTML = data[page].name;
ps[1].innerHTML = data[page].age;
ps[2].innerHTML = data[page].xuehao;
}
// Left arrow event
prev.onclick = function(){
if(page == 0){
return;
}
page -= 10;
for(var i=0;i<10;i++){
lis[i].innerHTML = data[i+page].name;
}
ps[0].innerHTML = data[page].name;
ps[1].innerHTML = data[page].age;
ps[2].innerHTML = data[page].xuehao;
}
</script>
</body>
</html>
JS
var str = ` Liang Fangyuan
Lixianwen
Qin Huihui
Pangxin
Luo Renli
Tangweiming
Yangjunquan
Long Guanxiong
Caoyinghao
Lan Yu
Huangguanbo
Liu Shuai
Zhangsiyun
Laiwenzhuo
Eujun
Lihanfeng
LAN Weige
Bao Shifu
Luhuaju
Panjunlong
Qiuyunxiang
Renchaorui
Suchenglin
Jiangxiongjie
Mo fanhao
Liangminjie
Huangruisheng
Luqifan
Ding Haifeng
Lijinxing
Mo Peiwen
Panguanjin
Weishuchong
Litianmin
Banlin
Li Nian
Wei Rongqi
Meng Jiawen
Lijinqing
Zhou Pengchao
Fucaiyu
Huang Yansong
Mengweiming
Liangyuee
Xuxianpiao
Xuzhengkun
Oudalio
Zhengqing
Lidexin
Lanjianyuan
Li Jinhui
Huangfengyi
Guan Peijia
Panglimin
Nonghao
Zeng Haixiang
Chenfujiu
Chen Keyu
Huang Yi
Huangqirui
Yangzhixin
Huangxiancai
Luhaiqi
Xuwenyi
Weiyuxin
Liang Yu
Chenminhao
Wuleyu
Liuyuchen
Xiepeiming
Huang Guoqing
Ning Yijian
WuWenTao
Huang Zhiyong
Gonghongwei
Li Wenlong
Nong Jianlei
Huangjunxiong
Huangwenxuan
Liukefan
Huang Jie
Tang Jie
Chenminghao
Liwanju
Chenliuyan
Huangliangyong
Master Lu
Yolang
Liangyongjie
Lubaozhe
Wuyuanhao
Sunke `;
function get(id){
return document.getElementById(id);
}
function log(msg){
console.log(msg)
}
var arr = str.split('\n');
var data = [];
for(var i=0;i<arr.length;i++){
data.push({
name:arr[i],
age: 15+parseInt(Math.random()*10),
xuehao: 123456789+parseInt(Math.random()*123456789),
})
}
log(data);
Renderings show 
边栏推荐
- Leetcode 176 The second highest salary (June 25, 2022)
- 力扣(LeetCode)176. 第二高的薪水(2022.06.25)
- 在哪里开基金帐户安全?
- 点击事件
- Vulhub replicate an ActiveMQ
- PCA and automatic encoder for dimension reduction of R language
- Learn Tai Chi Maker - mqtt (IV) server connection operation
- scrapy返回400
- 360 秒了解 SmartX 超融合基础设施
- Hardware creation principle of campus maker space
猜你喜欢

小米电视的网页和珠宝的网页

培育项目式Steam教育理念下的儿童创造力

Kotlin quick start

Inkscape如何将png图片转换为svg图片并且不失真

Oracle connectivity issues and Solutions

给网站添加“开放搜索描述“以适配浏览器的“站点搜索“

在UE内添加控制台工程(Programs)
HL7Exception: Can‘t XML-encode a GenericMessage. Message must have a recognized struct

计组笔记 数据表示与运算 校验码部分

stm32Cubemx:看门狗------独立看门狗和窗口看门狗
随机推荐
Good news | congratulations on the addition of 5 new committers in Apache linkage (incubating) community
jupyter notebook的插件安装以及快捷键
点击事件
小程序或者for循序要不要加key?
云计算基础-0
请求对象,发送请求
MySQL数据库基础
Utonmos adheres to the principle of "collection and copyright" to help the high-quality development of traditional culture
Components and routing
golang正则regexp包使用-06-其他用法(特殊字符转换、查找正则共同前缀、切换贪婪模式、查询正则分组个数、查询正则分组名称、用正则切割、查询正则字串)
The role of children's programming in promoting traditional disciplines in China
计组笔记 数据表示与运算 校验码部分
scrapy返回400
The golang regular regexp package uses -06- other usages (special character conversion, finding the regular common prefix, switching greedy mode, querying the number of regular groups, querying the na
[QT] custom control - air quality dashboard
进度条
Route jump: click the operation button of the list to jump to another menu page and activate the corresponding menu
Additional: brief description of hikaricp connection pool; (I didn't go deep into it, but I had a basic understanding of hikaricp connection pool)
学习太极创客 — MQTT(四)服务端连接操作
双碳红利+基建大年 | 图扑深耕水利水电绿色智能装备领域