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="小时加" onClick="add_hour();">
<input type="text" value="00" id="hour">
<input type="button" value="小时减" onClick="sub_hour();">
<br/>
<br/>
<input type="button" value="分钟加" onClick="add_minute();">
<input type="text" value="00" id="minute">
<input type="button" value="分钟减" onClick="sub_minute();">
</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);
}