-
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <title>无标题文档</title>
- <script src="prototype1.5.js" language="javascript" type="text/javascript"></script>
- <script src="wulin.js" language="javascript" type="text/javascript"></script>
- <style>
- input{
- width:120px;
- }
- .w1{
- width:120px;
- }
- .w2{
- width:65px;
- }
- .w3{
- width:135px;
- }
- .w5{
- width:80px;
- }
- .bw{
- width:50px;
- }
- body{font-size: 12px;}
- table{text-align:center}
- </style>
- </head>
- <body>
- <table width="766" bgcolor="#f5efe7" border="1" cellpadding="1" cellspacing="1">
- <tr>
- <td width="76">准备时间(秒)</td>
- <td width="122"><label>
- <input name="readyTime" type="text" style="width:60px" id="readyTime" value="100"/>
- <input type="button" name="Submit4" style="width:18px" value="+" onclick="plusSec()"/>
- <input type="button" name="Submit5" style="width:18px" value="-" onclick="subSec()"/>
- </label></td>
- <td width="117">
- <label>
- <div align="left">
- <input name="rb" id="rb1" style="width:20px" type="radio" value="1" checked="checked" />
- 当前时间压秒</div>
- </label></td>
- <td width="190"><label>
- <input type="text" name="calTime" id="calTime" class="w3"/>
- <input type="button" name="Submit42" style="width:35px" value="清除" onclick="cleanT('calTime')"/>
- </label></td>
- <td width="183"> </td>
- <td width="45"><label> </label></td>
- </tr>
- <tr>
- <td>作者:</td>
- <td>还是一样140-71(Version 0.3)</td>
- <td><label>
- <div align="left">
- <input type="radio" style="width:20px" name="rb" id="rb2" value="2" />
- 到达时间算出发</div>
- </label></td>
- <td><input type="text" name="arriveTime" id="arriveTime" class="w3"/>
- <input type="button" name="Submit43" style="width:35px" value="清除" onclick="cleanT('arriveTime')"/></td>
- <td><input type="button" name="Submit" value="计算" class="bw" onclick="cal()"/></td>
- <td> </td>
- </tr>
- </table>
- <table width="766" bgcolor="#f5efe7" border="1" cellpadding="1" cellspacing="1">
- <tbody id="table5">
- <tr>
- <td width="61">出击</td>
- <td width="139">昵称</td>
- <td width="86">行军时间</td>
- <td width="104">兵力优先时间(秒)</td>
- <td width="135">应该出发时间</td>
- <td width="138">应该到达时间</td>
- <td width="65"><input type="button" name="Submit2" value="添加" class="bw" onclick="addUser()"/></td>
- </tr>
- <tr>
- <td><label>
- <input type="checkbox" name="cb" value="" checked="checked" class="w2"/>
- </label></td>
- <td><input type="text" name="userName" class="w1"/></td>
- <td><input type="text" name="marchTime" class="w5"/></td>
- <td><input type="text" name="preferentTime" class="w2"/></td>
- <td><input type="text" name="shouldStartTime" class="w3"/></td>
- <td><input type="text" name="shouldEndTime" class="w3" /></td>
- <td>
- <input type="submit" name="Submit3" value="删除" class="bw" onclick="deleteUser(this.parentNode.parentNode)"/> </td>
- </tr>
- </tbody>
- </table>
- </body>
- </html>
- wulin.js
- created by sheng!
- at 2008-10-14
- 需要prototype1.5.js
- */
- function cal(){
- //alert('cal');
- //alert($('rb1').checked+" "+$('rb2').checked)
- if($('rb1').checked){cal1()}
- if($('rb2').checked){
- if($('arriveTime').value==''){alert('请输入到达时间!');return;}
- cal2();
- }
- }
- /**
- 当前时间压秒
- */
- function cal1(){
- //alert("最大行军时间"+getMaxMarchTime());
- var maxMarchTime=getMaxMarchTime();//最大行军时间
- var maxPreferentTime=getMaxPreferentTime();//最大优先时间
- //alert("最大优先时间"+maxPreferentTime);
- var readyTime=checkNaN(parseFloat($('readyTime').value));//准备时间
- //alert("准备时间"+readyTime);
- var maxWasteTime=maxMarchTime+readyTime+maxPreferentTime;//最大耗时=最大优先时间+准备时间+最大行军时间
- //var diffTime=;//出发差异时间=最大耗时-(行军时间-优先时间)
- //alert("最大耗时"+maxWasteTime);
- var cb=document.getElementsByName("cb");
- var marchTime=document.getElementsByName("marchTime");//行军时间
- var preferentTime=document.getElementsByName("preferentTime");//兵力优先时间(秒)
- var shouldStartTime=document.getElementsByName("shouldStartTime");//应该出发时间
- var shouldEndTime=document.getElementsByName("shouldEndTime");//应该到达时间
- //当'当前时间压秒'为空时,用系统时间,否则用输入的时间
- /*
- var curDate,curTimes;
- if($('calTime').value==''){
- curDate=new Date().getTime();
- curTimes=parseInt(curDate)/1000;
- $('calTime').value=secToDate(curTimes);
- }else{
- curDate=dateConvert($('calTime').value).getTime();
- curTimes=parseInt(curDate)/1000;
- }
- */
- var curDate=new Date().getTime();
- var curTimes=parseInt(curDate)/1000;
- $('calTime').value=secToDate(curTimes);
- for(var i=0;i<cb.length;i++){
- if(cb[i].checked){
- //出发差异时间=最大耗时-(行军时间+优先时间)
- var marchTimeTemp=strToSec(marchTime[i].value);//行军时间
- var preferentTimeTemp=checkNaN(parseFloat(preferentTime[i].value));//优先时间
- var diffTime=maxWasteTime-(marchTimeTemp+preferentTimeTemp);
- //应出发时间=当前时间+出发差异时间
- shouldStartTime[i].value=secToDate(curTimes+diffTime);
- //应到达时间=应出发时间+行军时间
- shouldEndTime[i].value=secToDate(curTimes+diffTime+marchTimeTemp);
- }
- }
- }
- /**
- 到达时间算出发
- */
- function cal2(){
- var arriveTimeMillisec=dateConvert($('arriveTime').value).getTime();//到达时间毫秒
- //alert(arriveTimeMillisec);
- var arriveTime=parseInt(arriveTimeMillisec)/1000;//到达时间秒
- var cb=document.getElementsByName("cb");
- var marchTime=document.getElementsByName("marchTime");//行军时间
- var preferentTime=document.getElementsByName("preferentTime");//兵力优先时间(秒)
- var shouldStartTime=document.getElementsByName("shouldStartTime");//应该出发时间
- var shouldEndTime=document.getElementsByName("shouldEndTime");//应该到达时间
- for(var i=0;i<cb.length;i++){
- if(cb[i].checked){
- //出发时间=到达时间-行军时间
- var marchTimeTemp=strToSec(marchTime[i].value);//行军时间
- var preferentTimeTemp=checkNaN(parseFloat(preferentTime[i].value));//优先时间出发
- var startTime=arriveTime-marchTimeTemp;
- //应出发时间=出发时间-优先时间
- shouldStartTime[i].value=secToDate(startTime-preferentTimeTemp);
- //应到达时间=到达时间-优先时间
- shouldEndTime[i].value=secToDate(arriveTime-preferentTimeTemp);
- }
- }
- }
- /*得到最大行军时间*/
- function getMaxMarchTime(){
- var cb=document.getElementsByName("cb");
- var marchTime=document.getElementsByName("marchTime");//行军时间
- //var preferentTime=document.getElementsByName("preferentTime");//兵力优先时间(秒)
- //var shouldStartTime=document.getElementsByName("shouldStartTime");//应该出发时间
- //var shouldEndTime=document.getElementsByName("shouldEndTime");//应该到达时间
- var maxMarchTime=0;//最大耗时(秒)=最大优先时间+准备时间+最大行军时间
- for(var i=0;i<cb.length;i++){
- if(cb[i].checked){
- var mt=strToSec(marchTime[i].value);
- if(maxMarchTime<mt){
- maxMarchTime=mt;
- }
- }
- }
- return maxMarchTime;
- }
- /*得到最大优先时间*/
- function getMaxPreferentTime(){
- var cb=document.getElementsByName("cb");
- //var marchTime=document.getElementsByName("marchTime");//行军时间
- var preferentTime=document.getElementsByName("preferentTime");//兵力优先时间(秒)
- //var shouldStartTime=document.getElementsByName("shouldStartTime");//应该出发时间
- //var shouldEndTime=document.getElementsByName("shouldEndTime");//应该到达时间
- var maxPreferentTime=0;//最大耗时(秒)=最大优先时间+准备时间+最大行军时间
- for(var i=0;i<cb.length;i++){
- if(cb[i].checked){
- var mt=parseFloat(preferentTime[i].value);
- if(maxPreferentTime<mt){
- maxPreferentTime=mt;
- }
- }
- }
- return maxPreferentTime;
- }
- //alert(strToSec("1:1:1"))
- /*时间转换秒*/
- function strToSec(str){
- var t=str.split(":");
- var h=parseFloat(t[0]);
- var m=parseFloat(t[1]);
- var s=parseFloat(t[2]);
- return h*3600+m*60+s;
- }
- function secToDate(sec){
- var d=new Date(sec*1000);
- var s=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate()+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
- return s;
- }
- /*添加成员*/
- function addUser(){
- var a = ' <tr> '
- +' <td><label> '
- +' <input type="checkbox" name="cb" value="" checked="checked" class="w2"/> '
- +' </label></td> '
- +' <td><input type="text" name="userName" class="w1"/></td> '
- +' <td><input type="text" name="marchTime" class="w5"/></td> '
- +' <td><input type="text" name="preferentTime" class="w2"/></td> '
- +' <td><input type="text" name="shouldStartTime" class="w3"/></td> '
- +' <td><input type="text" name="shouldEndTime" class="w3" /></td> '
- +' <td> '
- +' <input type="submit" name="Submit3" value="删除" class="bw" οnclick="deleteUser(this.parentNode.parentNode)"/> '
- +' </td> '
- +' </tr> ';
- //var templ=new Template(a);
- new Insertion.Bottom('table5', a);
- //alert(templ.evaluate(datas));
- //new Insertion.Bottom('table5', templ.evaluate(datas));
- }
- function deleteUser(id){
- $('table5').removeChild($(id));
- }
- function DateDemo(){
- var d, s = "Today's date is: "; // 声明变量。
- d = new Date(); // 创建 Date 对象。
- s += (d.getMonth() + 1) + "/"; // 获取月份。
- s += d.getDate() + "/"; // 获取日。
- s += d.getYear(); // 获取年份。
- //return d.getTime();
- //return(d); // 返回日期。toString()
- //return new Date(1216450850510).toLocaleString();
- //ar ds=1216450850510;
- var ds=1000;
- return new Date(ds).toString();
- }
- function checkNaN(value){
- if(value){
- return value;
- }
- return 0;
- }
- var secStep=10;//每次加/减的单位为10秒
- /**
- 加秒数
- */
- function plusSec(){
- var readyTime=checkNaN(parseFloat($('readyTime').value));//准备时间
- $('readyTime').value=readyTime+secStep;
- cal();
- }
- /**
- 减秒数
- */
- function subSec(){
- var readyTime=checkNaN(parseFloat($('readyTime').value));//准备时间
- $('readyTime').value=readyTime-secStep;
- cal();
- }
- /**cleanT*/
- function cleanT(t){
- $(t).value='';
- $(t).focus();
- }
- function dateConvert(str)
- {
- if(typeof str!="string") return null;
- var dt=str.match(/^(/d{1,4})-(/d{1,2})-(/d{1,2}) (/d{1,2}):(/d{1,2}):(/d{1,2})$/);//YYYY-MM-DD
- var newdate=new Date();
- if(dt==null) return null;
- var y,m,d;
- y=parseInt(dt[1],10);
- m=parseInt(dt[2],10);
- d=parseInt(dt[3],10);
- var hh,mm,ss;
- hh=parseInt(dt[4]);
- mm=parseInt(dt[5]);
- ss=parseInt(dt[6]);
- //alert(hh+":"+mm+":"+ss)
- if(m>12 || m<0)return null;
- if(d>0) {
- newdate.setFullYear(y);
- newdate.setDate(d);
- newdate.setMonth(m-1);
- newdate.setHours(hh);
- newdate.setMinutes(mm);
- newdate.setSeconds(ss);
- return newdate ;
- }else{
- return null;
- }
- }
- //alert(secToDate(parseInt(dateConvert('2008-10-14 10:57:12').getTime())/1000))
- //alert(dateConvert('2008-10-14 10:57:12').getTime())