JS对象
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JS对象</title>
</head>
<body>
<script>
//创建对象方法1
var obj1 = new Object();
obj1.name = 'WJF';
obj1.age = 17;
obj1.fa = function (data) {
console.log('传参:'+data);
};
console.log(obj1.name + '同学' + obj1.age + '岁了');
// alert(obj1.name + '同学' + obj1.age + '岁了');
console.log(obj1.fa('PHP中文网 www.php.cn'));
//创建对象方法2
var obj2 = {name: "WJF",email: "33703259@qq.com"};
obj2.age = 17;
console.log(obj2);
//v创建对象方法3
var obj3 = {
name:"WJF",
email: "33703259@qq.cn",
fa: function (data) {
console.log(data);
}
};
console.log(obj3.fa('6666'));
//4
var obj4 = {
name: "WJF",
age: 17,
get: function () {
console.log(obj4.age);
},
fa: function () {
console.log(obj4.name);
}
};
console.log(obj4.fa());
</script>
</body>
</html>
JS定时器
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JS定时器</title>
</head>
<body>
<script>
//setTimeout()执行一次
setTimeout(function () {
console.log('1000ms')
},1000);
//setInterval()重复执行
setInterval(function () {
console.log('1000ms重复')
},1000);
//clearInterval()消除定时器
var time = setInterval(function () {
console.log('重复1000ms')
},1000);
setTimeout(function () {
clearInterval(time)
},4000);
</script>
</body>
</html>
发送验证码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>发送验证码</title>
</head>
<body>
<button id="text">发送验证码</button>
<script>
var button = document.getElementById('text');
button.addEventListener('click',function () {
var text = document.getElementById('text').textContent;
var time = 60;
var val = setInterval(function () {
document.getElementById('text').textContent = time+'秒后重试';
time --;
if (time == 0){
clearInterval(val);
document.getElementById('text').textContent = text;
}
},1000);
});
</script>
</body>
</html>