北京的制作网站的公司有哪些,郑州代理记账,如何装wordpress,怎样新建网站文章目录JavaScript 高级实例集合创建一个欢迎 cookie简单的计时另一个简单的计时在一个无穷循环中的计时事件带有停止按钮的无穷循环中的计时事件使用计时事件制作的钟表创建对象的实例创建用于对象的模板JavaScript 高级实例集合 创建一个欢迎 cookie
源码
!DOCTYPE ht…
文章目录JavaScript 高级实例集合创建一个欢迎 cookie简单的计时另一个简单的计时在一个无穷循环中的计时事件带有停止按钮的无穷循环中的计时事件使用计时事件制作的钟表创建对象的实例创建用于对象的模板JavaScript 高级实例集合 创建一个欢迎 cookie
源码
!DOCTYPE html
html
head
meta charsetutf-8
title梁辰兴实例/title
/head
head
script
function setCookie(cname,cvalue,exdays){var d new Date();d.setTime(d.getTime()(exdays*24*60*60*1000));var expires expiresd.toGMTString();document.cookie cnamecvalue; expires;
}
function getCookie(cname){var name cname ;var ca document.cookie.split(;);for(var i0; ica.length; i) {var c ca[i].trim();if (c.indexOf(name)0) return c.substring(name.length,c.length);}return ;
}
function checkCookie(){var usergetCookie(username);if (user!){alert(Welcome again user);}else {user prompt(Please enter your name:,);if (user! user!null){setCookie(username,user,30);}}
}
/script
/head
body onloadcheckCookie()/body
/html运行效果
简单的计时
源码
!DOCTYPE html
html
head
meta charsetutf-8
title梁辰兴实例/title
/head
body
p点击按钮在等待 3 秒后弹出 Hello。/p
button onclickmyFunction()点我/button
script
function myFunction(){setTimeout(function(){alert(Hello)},3000);
}
/script
/body
/html运行效果
另一个简单的计时
源码
!DOCTYPE html
html
head
meta charsetutf-8
title梁辰兴实例/title
/head
head
script
function timedText(){var xdocument.getElementById(txt);var t1setTimeout(function(){x.value2 seconds},2000);var t2setTimeout(function(){x.value4 seconds},4000);var t3setTimeout(function(){x.value6 seconds},6000);
}
/script
/head
body
form
input typebutton value显示文本时间! onclicktimedText() /
input typetext idtxt /
/form
p点击上面的按钮输出的文本将告诉你2秒4秒6秒已经过去了。/p
/body
/html运行效果
在一个无穷循环中的计时事件
源码
!DOCTYPE html
html
head
meta charsetutf-8
title梁辰兴实例/title
script
var c0;
var t;
var timer_is_on0;
function timedCount(){document.getElementById(txt).valuec;cc1;tsetTimeout(timedCount(),1000);
}
function doTimer(){if (!timer_is_on){timer_is_on1;timedCount();}
}
/script
/head
body
form
input typebutton value开始计数! onClickdoTimer()
input typetext idtxt
/form
p单击按钮输入框将从0开始一直计数。/p
/body
/html运行效果
带有停止按钮的无穷循环中的计时事件
源码
!DOCTYPE html
html
head
meta charsetutf-8
title梁辰兴实例/title
script
var c0;
var t;
var timer_is_on0;
function timedCount(){document.getElementById(txt).valuec;cc1;tsetTimeout(function(){timedCount()},1000);
}
function doTimer(){if (!timer_is_on){timer_is_on1;timedCount();}
}
function stopCount(){clearTimeout(t);timer_is_on0;
}
/script
/head
body
form
input typebutton value开始计数! onclickdoTimer() /
input typetext idtxt /
input typebutton value停止计数! onclickstopCount() /
/form
p
单击开始计数按钮按下时开始计数输入框将从0开始一直计数。单击停止计数按钮按下时停止计数再次点击开始计数按钮又再次开始计数。
/p
/body
/html运行效果
使用计时事件制作的钟表
源码
!DOCTYPE html
html
head
meta charsetutf-8
title梁辰兴实例/title
script
function startTime(){var todaynew Date();var htoday.getHours();var mtoday.getMinutes();var stoday.getSeconds();// 在小于10的数字钱前加一个‘0’mcheckTime(m);scheckTime(s);document.getElementById(txt).innerHTMLh:m:s;tsetTimeout(function(){startTime()},500);
}
function checkTime(i){if (i10){i0 i;}return i;
}
/script
/head
body onloadstartTime()
div idtxt/div
/body
/html运行效果
创建对象的实例
源码
!DOCTYPE html
html
head
meta charsetutf-8
title梁辰兴实例/title
/head
body
script
person{firstname:John,lastname:Doe,age:50,eyecolor:blue}
document.write(person.firstname is person.age years old.);
/script
/body
/html运行效果
创建用于对象的模板
源码
!DOCTYPE html
html
head
meta charsetutf-8
title梁辰兴实例/title
/head
body
script
function person(firstname,lastname,age,eyecolor){this.firstnamefirstname;this.lastnamelastname;this.ageage;this.eyecoloreyecolor;
}
myFathernew person(John,Doe,50,blue);
document.write(myFather.firstname is myFather.age years old.);
/script
/body
/html运行效果