个人博客
JavaScript 案例21
Date 获取 年月日星期
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Date</title>
</head>
<body>
<script>
/**
* var oDate = new Date()
* getFullYear() 获取时
* getMonth() 获取分钟
* getDate() 获取秒
* getDay() 获取星期
* */
var oDate = new Date();
alert(oDate.getFullYear());
alert(oDate.getMonth());//获取月份是从 0 开始计数的,月份需要加 1
alert(oDate.getDate());
alert(oDate.getDay());//获取星期几,从 0 开始计数,代表周日
</script>
</body>
</html>
JavaScript 案例22
延时提示框 鼠标移入移出提示延时消失
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>延时提示框</title>
<style>
#div1{width: 30px; height: 30px; background: cornflowerblue;float: left;margin: 20px;}
#div2{width: 100px; height: 200px; background: aqua;float: left;margin: 20px;display: none}
</style>
</head>
<body>
<div id="div1">
</div>
<div id="div2">
</div>
<script>
var oDiv1 = document.getElementById('div1');
var oDiv2 = document.getElementById('div2');
var timer;
oDiv1.onmouseover = oDiv2.onmouseover = function () {
clearTimeout(timer)
oDiv2.style.display = 'block';
}
oDiv1.onmouseout =oDiv2.onmouseout = function () {
timer = setTimeout(function () {
oDiv2.style.display = 'none';
},500)
}
//函数类似可以合并到上面去
// oDiv2.onmouseover = function () {
// clearTimeout(timer);
// }
// oDiv2.onmouseout = function () {
// timer = setTimeout(function () {
// oDiv2.style.display = 'none';
// },500)
//
// }
</script>
</body>
</html>