time.html代码:
复制代码 代码如下:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<script type="text/javascript" src="jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="time.js"></script>
</head>
<body>
<input type="button" value="小时加">
<input type="text" value="00" id="hour">
<input type="button" value="小时减">
<br/>
<br/>
<input type="button" value="分钟加">
<input type="text" value="00" id="minute">
<input type="button" value="分钟减">
</body>
</html>
time.js代码:
复制代码 代码如下:
function add_num(a,b,c){
if(c<a){
c++;
}
else{
c=b;
}
if(c<=9&&c>=0){
c="0"+c;
}
return c;
}
function sub_num(a,b,c){
if(c>a){
c--;
}
else{
c=b;
}
if(c<=9&&c>=0){
c="0"+c;
}
return c;
}
function add_hour(){
var current_num=$("#hour").attr("value");
current_num=add_num(23,0,current_num);
$("#hour").attr("value",current_num);
}
function sub_hour(){
var current_num=$("#hour").attr("value");
current_num=sub_num(0,23,current_num);
$("#hour").attr("value",current_num);
}
function add_minute(){
var current_num=$("#minute").attr("value");
current_num=add_num(59,0,current_num);
$("#minute").attr("value",current_num);
}
function sub_minute(){
var current_num=$("#minute").attr("value");
current_num=sub_num(0,59,current_num);
$("#minute").attr("value",current_num);
}