怎么管理网站的内容我要发布信息
知识点:
js使用Date对象:
new Date()//得到当前的时间
date.getSeconds();//得到当前秒数
currentDate.getFullYear//得到当前年份
currentDate.getMonth//获取当前月份
currentDate.toDateString//获取当前日期
< button onclick = “函数时间” >点击按钮式触发事件
alert 提示框
prompt 提示框
confirm 确认框
(在确认以后可以执行动作,比如在删除的时候)
open 打开新的界面,比如:
open(“http://www.biadu.com”)
setTimeout(函数名称,延迟时间(单位是毫秒));建议如果只用一次,可以使用匿名函数
h1.InnerHTML();//将h1改变为其他格式,比如:h1.InnerHTML = “<span style = ‘color : red’;>” + time + “”
停止时间:clearInterval(需要停止的时间);
案例:每秒输出,当秒数为0时变为红色,当点击停止按钮的时候停止计时
效果如下:
<!DOCTYPE html>
<html><head><meta charset="utf-8"><title></title></head><body><div id = "dv">我是一个div</div><button onclick = "test_alert();">提示框</button><button onclick = "test_prompt();">输入框</button><button onclick = "test_confirm();">确认框</button><input type="button" value = "百度" onclick = "baidu();"><h1 id = "h1"></h1><button onclick = "stopTime();">停止函数</button><script type="text/javascript">function test_alert() {alert("我是一个警告框");}function test_confirm() {var result = confirm("真的确定要点吗");if(result){var v = document.getElementById("dv");dv.style.color = "red";dv.innerHTML = "我是红色的哦哈哈哈哈哈哈哈哈哈哈";}else{console.log("没事点尼玛呢?");alert("没事点尼玛呢??");}}function test_prompt() {alert(prompt("请输入姓名"));}function baidu() {open("http://www.baidu.com");}// setTimeout(function(){// alert("对不起久等了");// }, 3000);function showTime() {// 拿到当前时间var date = new Date();var time = date.toLocaleString();// console.log(time);var h1 = document.getElementById("h1");h1.innerHTML = time;var sec = date.getSeconds();if(sec % 10 == 0){h1.innerHTML = "<span style = 'color: red';> " + time + "</span>";}}var timeout = setInterval(showTime, 1000);function stopTime() {clearInterval(timeout);}</script></body>
</html>