案例:点击显示时间
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>JavaScript</title> </head> <body> <div class="box" style="width: 500px;height: 30px;background-color: #f0c674; line-height: 30px;text-align: center" onclick="myClick(this)">点击这里显示时间</div> <script> function myClick(x) { var date = new Date(); console.log(date); x.style.backgroundColor = 'red'; x.style.color = 'white'; x.innerHTML= date; } </script> </body> </html>
点击前:
点击后:
小总结:
熟悉js操作html元素;
熟悉js操作css样式;
熟悉时间的获取;