zythum
2011-04-21 18:00:05 +08:00
虽然dreampuf同学已经该处代码了。。。朱一也继续给个。。。以供参考:同能与dreampuf相同,点击加一,长按一秒减一。
<!DOCTYPE HTML>
<html lang="ru-RU">
<head>
<title>demo</title>
<meta charset="UTF-8">
<script type="text/javascript">
function SetCookie(name,value)
{
var Days = 30;
var exp = new Date();
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)
{
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if(arr != null)
return unescape(arr[2]);
return null;
}
window.onload = function(){
var btn = document.getElementsByTagName('button')[0];
var span = document.getElementsByTagName('span')[0];
var time;
var num = getCookie('thiscookienum');
span.innerHTML = (num == null?num=0:num*=1);
btn.onmousedown = function(){
num+=1;
time = setTimeout(function(){
num -= 2;
},1000);
}
btn.onmouseup = function(){
clearTimeout(time);
span.innerHTML = num;
SetCookie('thiscookienum',num);
}
}
</script>
</head>
<body>
<button>点我 </button><span>0</span>
</body>
</html>