发表于: 2023-02-20 21:21:47
0 289
今天的js:
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<!-- <input type="text" value="电脑">-->
<input type="checkbox" name="" id="">
<!-- disabled 禁用-->
<button></button>
<script>
//获取元素
// const uname = document.querySelector('input')
//获取表单值
// console.log(uname.value)
// console.log(uname.innerHTML) innerHTML 得不到表单的内容
//设置表单值
// uname.value = '我要买电脑'
// console.log(uname.type)
// uname.type = 'password'
//获取元素
const ipt = document.querySelector('input')
//勾选
// ipt.checked = true
// ipt.checked = 'true' 会选中,不提倡 有隐式转换
//获取
const button = document.querySelector('button')
console.log(button.disabled) //默认false 禁用吗? 不禁用
button.disabled = true //禁用
</script>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div data-id="1" data-spm="不知道">1</div>
<div data-id="2">2</div>
<div data-id="3">3</div>
<div data-id="4">4</div>
<div data-id="5">5</div>
<script>
const one = document.querySelector('div')
console.log(one.dataset)
console.log(one.dataset.id) //dataset 集合console.log(one.dataset.spm) //dataset 集合d
// setInterval(函数, 间隔时间)
// setInterval(function () {
// console.log('一秒执行一次')
// }, 1000)
function fn() {
console.log('一秒执行一次')
}
// setInterval(函数, 间隔时间) 函数名不要加小括号
let n = setInterval(fn, 1000)
console.log(n)
//关闭定时器 clearInterval(变量名)
clearInterval(n)</script>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<textarea name="" id="" cols="30" rows="10">
用户注册协议
欢迎注册成为京东用户!在您注册处过程中,您需要完成我们的注册流程并通过
【请您注意】如果您不同意以下全部协议或任何条款约定,请你停止注册。
</textarea>
<br>
<button class="btn" disabled>我已经阅读用户协议(5)</button>
<script>
//获取元素
const btn = document.querySelector('.btn')
//倒计时
let i = 5
//开启定时器
let n = setInterval(function () {
i--
btn.innerHTML = `我已经阅读用户协议(${i})`
if(i === 0) {
clearInterval(n)
btn.disabled = false
btn.innerHTML = `我已同意`
}
}, 1000)
</script>
</body>
</html>
案例练习:
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
* {
box-sizing: border-box;
}
.slider {
width: 560px;
height: 400px;
overflow: hidden;
}
.slider-wrapper {
width: 100%;
height: 320px;
}
.slider-wrapper img {
width: 100%;
height: 100%;
display: block;
}
.slider-footer {
height: 80px;
background-color: rgb(100, 67, 68);
padding: 12px 12px 0 12px;
position: relative;
}
.slider-footer .toggle {
position: absolute;
right: 0;
top: 12px;
display: flex;
}
.slider-footer .toggle button {
margin-right: 12px;
width: 28px;
height: 28px;
appearance: none;
border: none;
background: rgba(255, 255, 255, 0.1);
color: #fff;
cursor: pointer;
}
.slider-footer .toggle button:hover {
background: rgba(255, 255, 255, 0.2);
}
.slider-footer p {
margin: 0;
color: #fff;
font-size: 18px;
margin-bottom: 10px;
}
.slider-indicator {
margin: 0;
padding: 0;
list-style: none;
display: flex;
align-items: center;
}
.slider-indicator li {
width: 8px;
height: 8px;
margin: 4px;
border-radius: 50%;
background: #fff;
opacity: 0.4;
cursor: pointer;
}
.slider-indicator li.active {
width: 12px;
height: 12px;
opacity: 1;
}
</style>
</head>
<body>
<div class="slider">
<div class="slider-wrapper">
<img src="../../js2-DOM/images/1.jpg" alt="">
</div>
<div class="slider-footer">
<p>雅儿贝德</p>
<ul class="slider-indicator">
<li class="active"></li>
<li></li>
<li></li>
<li></li>
</ul>
<div class="toggle">
<button class="prev"><</button>
<button class="next">></button>
</div>
</div>
</div>
<script>
//更好p里面的字
// 初始数据
const sliderData = [
{url: `../../js2-DOM/images/1.jpg`, title: `动漫角色图`, color: `rgb(67, 98, 92)`},
{url: `../../js2-DOM/images/2.jpg`, title: `狗子`, color: `rgb(166, 131, 143)`},
{url: `../../js2-DOM/images/3.jpg`, title: `猫猫`, color: `rgb(53, 29, 25)`},
{url: `../../js2-DOM/images/4.jpg`, title: `动漫壁纸图`, color: `rgb(99, 72, 114)`}
]
//获取元素
const img = document.querySelector('.slider-wrapper img')
const p = document.querySelector('.slider-footer p')
let i = 0
//开启定时器
setInterval(function () {
i++
//无缝衔接位置
if (i >= sliderData.length) {
i = 0
}
console.log(i)
//更换图
img.src = sliderData[i].url
p.innerHTML = sliderData[i].title
//小圆点
// 先删除以前的 active
document.querySelector(`.slider-indicator .active`).classList.remove(`active`)
//只让当前 li添加 active
document.querySelector(`.slider-indicator li:nth-child(${i + 1})`).classList.add('active')
}, 1000)
</script>
</body>
</html>
评论