简单倒计时
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<p></p>
<p></p>
<p></p>
<script !src="">
let p = document.querySelectorAll("p")
let xs = p[0];
let fz = p[1]
let m = p[2]
let s = 3;
let f = 0;
let i = 0;
var ms = s * 60 * 60 + f * 60 + i
var temer = setInterval(function () {
if (ms > 0) {
ms--
} else {
clearInterval(temer)
}
var s = parseInt(ms / (60 * 60));
var f = parseInt((ms - s * 60 * 60) / 60);
var i = ms - s * 60 * 60 - f * 60
xs.innerHTML = s > 9 ? s : "0" + s
fz.innerHTML = f > 9 ? f : "0" + f
m.innerHTML = i > 9 ? i : "0" + i
}, 100)
</script>
</body>
</html>
轮播图显示隐藏带圆圈
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta content="IE=edge" http-equiv="X-UA-Compatible">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<title>Document</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
* {
padding: 0;
margin: 0;
list-style: none;
text-decoration: none;
}
section {
width: 100%;
height: 500px;
position: relative;
}
main {
width: 300px;
height: 200px;
border: 1px solid;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
}
div {
width: 300px;
height: 200px;
position: absolute;
top: 0;
display: none;
}
.xs {
display: block;
}
main>a:nth-child(1) {
position: absolute;
left: 0;
top: 50%;
}
main>a:nth-child(2) {
position: absolute;
right: 0;
top: 50%;
}
ul {
display: flex;
position: absolute;
bottom: 0;
}
li {
width: 20px;
height: 20px;
border-radius: 50%;
border: 1px solid;
background-color: #ccc;
}
.red {
background-color: red;
}
a {
width: 20px;
height: 20px;
opacity: 0;
color: white;
z-index: 3;
}
div:nth-of-type(1) {
background-color: khaki;
}
h2 {
color: white;
}
div:nth-of-type(2) {
background-color: deepskyblue;
}
div:nth-of-type(3) {
background-color: blue;
}
div:nth-of-type(4) {
background-color: yellow;
}
div:nth-of-type(5) {
background-color: pink;
}
div:nth-of-type(6) {
background-color: green;
}
div:nth-of-type(7) {
background-color: orange;
}
div:nth-of-type(8) {
background-color: darkviolet;
}
</style>
</head>
<body>
<section>
<main>
<a href="javascript:;"><</a>
<a href="javascript:;">></a>
<div class="xs">
<h2>第一张图片信息</h2>
</div>
<div>
<h2>第二张图片信息</h2>
</div>
<div>
<h2>第三张图片信息</h2>
</div>
<div>
<h2>第四张图片信息</h2>
</div>
<div>
<h2>第五张图片信息</h2>
</div>
<div>
<h2>第六张图片信息</h2>
</div>
<div>
<h2>第七张图片信息</h2>
</div>
<div>
<h2>第八张图片信息</h2>
</div>
<ul>
</ul>
</main>
</section>
<script>
var zb = document.querySelector("main>a:nth-child(1)")
var a = document.querySelectorAll("a")
var yb = document.querySelector("main>a:nth-child(2)")
var main = document.querySelector("main")
var div = document.querySelectorAll("div")
var ul = document.querySelector("ul")
let index = 0;
var xj = 0;
function tupian() {
document.querySelector(".xs").classList.remove("xs")
div[index].classList.add("xs")
}
for (let i = 0; i < div.length; i++) {
var li = document.createElement("li")
ul.appendChild(li)
li.setAttribute('index', i);
li.addEventListener("click", function () {
for (var j = 0; j < ul.children.length; j++) {
ul.children[j].className = " "
}
this.className = "red"
index = this.getAttribute("index")
xj = index
tupian()
})
}
ul.children[0].className = "red"
zb.addEventListener("click", function () {
index--;
xj--;
if (index < 0) {
index = div.length - 1
xj = div.length - 1
}
for (var j = 0; j < ul.children.length; j++) {
ul.children[j].className = " "
}
ul.children[xj].className = "red"
tupian()
})
yb.addEventListener("click", function () {
index++;
xj++;
if (index > div.length - 1) {
index = 0;
xj = 0
}
for (var j = 0; j < ul.children.length; j++) {
ul.children[j].className = " "
}
ul.children[xj].className = "red"
tupian()
})
let temer = setInterval(function () {
yb.click();
}, 1000)
main.addEventListener("mouseover", function () {
zb.style.opacity = "1"
yb.style.opacity = "1"
clearInterval(temer)
})
main.addEventListener("mouseout", function () {
zb.style.opacity = "0"
yb.style.opacity = "0"
temer = setInterval(function () {
yb.click()
}, 1000)
})
</script>
</body>
</html>
三级联动(全部渲染)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>地址栏</title>
</head>
<style>
</style>
<body>
<select name="" id="s1"></select>
<select name="" id="s2"></select>
<select name="" id="s3"></select>
</body>
<script src="./js/三级联动的数据.js"></script>
<script>
let index=0
let index2=0
var selects = document.querySelectorAll("select")
data.forEach(function (value) {
var option = document.createElement('option')
option.innerHTML= value.name
selects[0].appendChild(option)
})
for (let i = 0
var option3 = document.createElement("option")
option3.innerHTML = data[0].children[0].name
selects[1].appendChild(option3)
}
for (let i = 0
var option2 = document.createElement("option")
option2.innerHTML = data[0].children[0].children[i].name
selects[2].appendChild(option2)
}
selects[0].addEventListener("change", function (e) {
//遍历清除其他option,不清除就会滞留上个元素的option
document.querySelectorAll("
value.remove()
})
//第二层联动 selectedIndex当前对象(select第一层)的索引值
//获取select当前对象的索引
index = this.selectedIndex
//创建option并加入下拉框
data[index].children.forEach(function (value) {
var option = document.createElement('option')
option.innerText = value.name
selects[1].appendChild(option)
})
//第三层联动
document.querySelectorAll("
value.remove()
})
data[index].children[0].children.forEach(function (value) {
var option4 = document.createElement('option')
option4.innerText = value.name
selects[2].appendChild(option4)
})
}
)
selects[1].addEventListener("change", function () {
document.querySelectorAll("
value.remove()
})
index2 = this.selectedIndex
data[index].children[index2].children.forEach(function (value) {
var option4 = document.createElement('option')
option4.innerText = value.name
selects[2].appendChild(option4)
// console.log(data[index].children[0].children)
})
})
</script>
</html>
三级联动(非全部渲染)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
.bigBox {
margin-top: 5vh;
height: 90vh;
}
.box {
margin: 0 auto;
border: 1px solid;
height: 220px;
width: 1250px;
overflow: auto;
}
ul {
width: 1250px;
display: flex;
justify-content: space-arounds;
flex-wrap: wrap;
}
li {
list-style: none;
width: 200px;
height: 30px;
text-align: center;
line-height: 30px;
border: 1px solid;
}
</style>
<script src="./data.js"></script>
</head>
<body>
<div class="bigBox">
<div class="no1 box">
<ul></ul>
</div>
<div class="no2 box">
<ul></ul>
</div>
<div class="no3 box">
<ul></ul>
</div>
</div>
<script>
var no1Ul = document.querySelector(".no1>ul")
var no2Ul = document.querySelector(".no2>ul")
var no3Ul = document.querySelector(".no3>ul")
function addLi(value, Ul) {
for (let i = 0; i < value.length; i++) {
var li = document.createElement("li")
li.innerText = value[i].name
Ul.appendChild(li)
}
}
function removeLi(Ul) {
Ul.innerHTML = ""
}
addLi(data, no1Ul);
console.log(no1Ul.children);
var no1Li = document.querySelectorAll(".no1>ul>li")
for (let i = 0; i < no1Li.length; i++) {
no1Li[i].onclick = function () {
removeLi(no2Ul)
removeLi(no3Ul)
addLi(data[i].children, no2Ul)
var no2Li = document.querySelectorAll(".no2>ul>li")
console.log(no2Li);
for (let j = 0; j < no2Li.length; j++) {
no2Li[j].onclick = function () {
removeLi(no3Ul)
addLi(data[i].children[j].children, no3Ul)
}
}
}
}
</script>
</body>
</html>
三级联动的js文件
这个网上找地区的json文件即可,定义初始值var data={}
放大镜
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
list-style: none;
text-decoration: none;
}
#__bs_notify__ {
display: none !important;
}
nav {
display: flex;
}
.xt {
width: 400px;
height: 400px;
border: 1px solid;
position: relative;
}
.xt>img {
width: 190px;
height: 257px;
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
margin: auto;
}
.datu {
width: 400px;
height: 400px;
margin-left: 50px;
border: 1px solid;
position: relative;
overflow: hidden;
}
.datu>p {
position: absolute;
left: 0;
top: 0;
width: 700px;
height: 700px;
z-index: 3;
}
.datu>p>img {
width: 380px;
height: 514px;
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
margin: auto;
}
.mask {
width: 100px;
height: 100px;
position: absolute;
top: 0;
left: 0;
background-color: pink;
opacity: .5;
display: none;
}
</style>
</head>
<body>
<nav>
<div class="xt">
<img src="https://www.apple.com.cn/v/iphone/home/bk/images/overview/compare/compare_iphone_14_pro__cjmfbiggqhpy_large.jpg"
alt="">
<p class="mask"></p>
</div>
<div class="datu">
<p>
<img src="https://www.apple.com.cn/v/iphone/home/bk/images/overview/compare/compare_iphone_14_pro__cjmfbiggqhpy_large.jpg"
alt="">
</p>
</div>
</nav>
<script>
let mask = document.querySelector(".mask");
let datu = document.querySelector(".datu");
let xt = document.querySelector(".xt");
let p = document.querySelector(".datu>p")
let nav = document.querySelector("nav")
xt.addEventListener("mouseover", function () {
mask.style.display = "block"
datu.style.display = "block"
})
xt.addEventListener("mouseout", function () {
mask.style.display = "none"
datu.style.display = "none"
})
xt.addEventListener("mousemove", function (e) {
var x = e.pageX - this.offsetLeft;
var y = e.pageY - this.offsetTop;
var maskx = x - mask.offsetWidth / 2
var masky = y - mask.offsetHeight / 2
var max = xt.offsetWidth - mask.offsetWidth
if (maskx <= 0) {
maskx = 0
} else if (maskx >= max) {
maskx = max;
}
if (masky <= 0) {
masky = 0
} else if (masky >= max) {
masky = max;
}
mask.style.left = maskx + "px"
mask.style.top = masky + "px"
var imgs = datu.offsetWidth - p.offsetWidth
var bigx = maskx * imgs / max
var bigy = masky * imgs / max
p.style.left = bigx + "px"
p.style.top = bigy + "px"
})
</script>
</body>
</html>
随机验证码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
</style>
</head>
<body>
<script>
function createVerificationCode() {
var code = "";
var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'a', "b", "c", "d", "e", "f", 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z'];
for (var i = 0; i < 4; i++) {
var result = parseInt(Math.random() * arr.length);
code += arr[result];
}
return code;
}
console.log(createVerificationCode());
</script>
</body>
</html>