历史操作

var historyMap = new HashMap();
var nowHisNos=0;//当前所处的历史数
var creHisNos=1;//创建的数目
var focusValue="";//获取焦点前的值
//操作对象
function HistoryObj(nos,obj,objHtml){
this.nos =  nos;
this.obj = obj;
this.objHtml = objHtml;
}
//保存操作历史
function saveHistory(obj){
var historyob =  new HistoryObj(creHisNos,obj,obj.innerHTML);
historyMap.put(creHisNos,historyob);
nowHisNos = creHisNos;
creHisNos++;
}

//返回历史 nos 第几步
function goHistorys(nos){
var goNos=  nowHisNos+parseInt(nos);
if(isNaN(goNos) || goNos <= 0 ){//如果输入错误,并且小于0
return;
}
if(goNos>historyMap.size()){//超过也不行
return;
}
nowHisNos = goNos;
if(historyMap.containsKey(nowHisNos)){//如果存在该步骤
  var historyob=historyMap.get(nowHisNos).value;
  //alert(historyob.obj+""+historyob.nos+"|"+historyob.objHtml);
historyob.obj.innerHTML = historyob.objHtml;
historyob.obj.style.background='red';
if(historyMap.containsKey(nowHisNos+1)){
var nexthistoryob=historyMap.get(nowHisNos+1).value;
nexthistoryob.obj.style.background='';
nexthistoryob.obj.innerHTML = nexthistoryob.objHtml;
}
 
}else {
alert("不包含key:"+nowHisNos);
}
}


<html>
<head>
<script language='javascript' charset='utf-8' src='framework.js'></script>
<script language='javascript' charset='utf-8' src='historyUtil.js'></script>
</head>
<body>
<table >
<tr>
<td onclick="saveHistory(this)" >
<input type="text" value="9:00" />
</td>
<td  onclick="saveHistory(this)"> 
<input type="text" value="10:00"/> 
</td>
</tr>
<tr>
<td onclick="saveHistory(this)">
<input type="text" value="11:00" /> 
</td>
<td onclick="saveHistory(this)">
<input type="text" value="12:00" /> 
</td>
</tr>
<tr>
<td colspan="2">
<input  onclick="goHistorys(-1)"  value="返回上一步" style="CURSOR:pointer;width: 70px"/>
跳到第<input  onclick="goHistorys(this.value)"  value="" style="CURSOR:pointer;width: 80px"/>步
<input  onclick="goHistorys(1)"  value="返回下一步" style="CURSOR:pointer;width: 70px"/>
</td>
</tr>
</table>
</body>
</html>

你可能感兴趣的:(操作)