武林三国压秒

 
    1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    2. <html xmlns="http://www.w3.org/1999/xhtml">
    3. <head>
    4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    5. <title>无标题文档</title>
    6. <script src="prototype1.5.js" language="javascript" type="text/javascript"></script>
    7. <script src="wulin.js" language="javascript" type="text/javascript"></script>
    8. <style>
    9. input{
    10.     width:120px;
    11.     
    12. }
    13. .w1{
    14. width:120px;
    15. }
    16. .w2{
    17. width:65px;
    18. }
    19. .w3{
    20. width:135px;
    21. }
    22. .w5{
    23. width:80px;
    24. }
    25. .bw{
    26. width:50px;
    27. }
    28. body{font-size: 12px;}
    29. table{text-align:center}
    30. </style>
    31. </head>
    32.     
    33. <body>
    34. <table width="766"  bgcolor="#f5efe7" border="1" cellpadding="1" cellspacing="1">
    35.   <tr>
    36.     <td width="76">准备时间(秒)</td>
    37.     <td width="122"><label>
    38.       <input name="readyTime" type="text" style="width:60px" id="readyTime" value="100"/>
    39.       <input type="button" name="Submit4" style="width:18px"  value="+" onclick="plusSec()"/>
    40.       <input type="button" name="Submit5" style="width:18px"  value="-" onclick="subSec()"/>
    41.     </label></td>
    42.     <td width="117">
    43.       <label>
    44.       <div align="left">
    45.         <input name="rb"  id="rb1" style="width:20px" type="radio" value="1" checked="checked" />
    46.         当前时间压秒</div>
    47.     </label></td>
    48.     <td width="190"><label>
    49.       <input type="text" name="calTime" id="calTime" class="w3"/>
    50.       <input type="button" name="Submit42" style="width:35px"  value="清除" onclick="cleanT('calTime')"/>
    51.     </label></td>
    52.     <td width="183"> </td>
    53.     <td width="45"><label> </label></td>
    54.   </tr>
    55.   <tr>
    56.     <td>作者:</td>
    57.     <td>还是一样140-71(Version 0.3)</td>
    58.     <td><label>
    59.       <div align="left">
    60.         <input type="radio" style="width:20px" name="rb" id="rb2" value="2" />
    61.         到达时间算出发</div>
    62.     </label></td>
    63.     <td><input type="text" name="arriveTime" id="arriveTime" class="w3"/>
    64.     <input type="button" name="Submit43" style="width:35px"  value="清除" onclick="cleanT('arriveTime')"/></td>
    65.     <td><input type="button" name="Submit" value="计算" class="bw" onclick="cal()"/></td>
    66.     <td> </td>
    67.   </tr>
    68. </table>
    69. <table width="766" bgcolor="#f5efe7"  border="1" cellpadding="1" cellspacing="1">
    70. <tbody id="table5">
    71.   <tr>
    72.     <td width="61">出击</td>
    73.     <td width="139">昵称</td>
    74.     <td width="86">行军时间</td>
    75.     <td width="104">兵力优先时间(秒)</td>
    76.     <td width="135">应该出发时间</td>
    77.     <td width="138">应该到达时间</td>
    78.     <td width="65"><input type="button" name="Submit2" value="添加" class="bw" onclick="addUser()"/></td>
    79.   </tr>
    80.   <tr>
    81.     <td><label>
    82.       <input type="checkbox" name="cb" value="" checked="checked" class="w2"/>
    83.     </label></td>
    84.     <td><input type="text" name="userName" class="w1"/></td>
    85.     <td><input type="text" name="marchTime" class="w5"/></td>
    86.     <td><input type="text" name="preferentTime"  class="w2"/></td>
    87.     <td><input type="text" name="shouldStartTime" class="w3"/></td>
    88.     <td><input type="text" name="shouldEndTime" class="w3" /></td>
    89.     <td>
    90.       <input type="submit" name="Submit3" value="删除" class="bw" onclick="deleteUser(this.parentNode.parentNode)"/>    </td>
    91.   </tr>
    92.   </tbody>
    93. </table>
    94. </body>
    95. </html>
    /*
  1.     wulin.js
  2.     created by sheng!
  3.     at 2008-10-14
  4.     需要prototype1.5.js
  5. */
  6. function cal(){
  7.     //alert('cal');
  8.     //alert($('rb1').checked+" "+$('rb2').checked)
  9.     if($('rb1').checked){cal1()}
  10.     if($('rb2').checked){
  11.         if($('arriveTime').value==''){alert('请输入到达时间!');return;}
  12.         cal2();
  13.     }
  14. }
  15. /**
  16.     当前时间压秒
  17. */
  18. function cal1(){
  19.     //alert("最大行军时间"+getMaxMarchTime());
  20.     var maxMarchTime=getMaxMarchTime();//最大行军时间
  21.     var maxPreferentTime=getMaxPreferentTime();//最大优先时间
  22.     //alert("最大优先时间"+maxPreferentTime);
  23.     var readyTime=checkNaN(parseFloat($('readyTime').value));//准备时间
  24.     //alert("准备时间"+readyTime);
  25.     var maxWasteTime=maxMarchTime+readyTime+maxPreferentTime;//最大耗时=最大优先时间+准备时间+最大行军时间
  26.     //var diffTime=;//出发差异时间=最大耗时-(行军时间-优先时间)
  27.     //alert("最大耗时"+maxWasteTime);
  28.     
  29.     var cb=document.getElementsByName("cb");
  30.     var marchTime=document.getElementsByName("marchTime");//行军时间
  31.     var preferentTime=document.getElementsByName("preferentTime");//兵力优先时间(秒)
  32.     var shouldStartTime=document.getElementsByName("shouldStartTime");//应该出发时间
  33.     var shouldEndTime=document.getElementsByName("shouldEndTime");//应该到达时间
  34.     
  35.     //当'当前时间压秒'为空时,用系统时间,否则用输入的时间
  36.     /*
  37.     var curDate,curTimes;
  38.     if($('calTime').value==''){
  39.         curDate=new Date().getTime();
  40.         curTimes=parseInt(curDate)/1000;
  41.         $('calTime').value=secToDate(curTimes);
  42.     }else{
  43.         curDate=dateConvert($('calTime').value).getTime();
  44.         curTimes=parseInt(curDate)/1000;
  45.     }
  46.     */
  47.     var curDate=new Date().getTime();
  48.     var curTimes=parseInt(curDate)/1000;
  49.     $('calTime').value=secToDate(curTimes);
  50.     for(var i=0;i<cb.length;i++){
  51.         if(cb[i].checked){
  52.             //出发差异时间=最大耗时-(行军时间+优先时间)
  53.             var marchTimeTemp=strToSec(marchTime[i].value);//行军时间
  54.             var preferentTimeTemp=checkNaN(parseFloat(preferentTime[i].value));//优先时间
  55.             var diffTime=maxWasteTime-(marchTimeTemp+preferentTimeTemp);
  56.             //应出发时间=当前时间+出发差异时间
  57.             shouldStartTime[i].value=secToDate(curTimes+diffTime);
  58.             //应到达时间=应出发时间+行军时间
  59.             shouldEndTime[i].value=secToDate(curTimes+diffTime+marchTimeTemp);
  60.         }   
  61.     }   
  62. }
  63. /**
  64.     到达时间算出发
  65. */
  66. function cal2(){
  67.     
  68.     var arriveTimeMillisec=dateConvert($('arriveTime').value).getTime();//到达时间毫秒
  69.     //alert(arriveTimeMillisec);
  70.     var arriveTime=parseInt(arriveTimeMillisec)/1000;//到达时间秒
  71.     
  72.     var cb=document.getElementsByName("cb");
  73.     var marchTime=document.getElementsByName("marchTime");//行军时间
  74.     var preferentTime=document.getElementsByName("preferentTime");//兵力优先时间(秒)
  75.     var shouldStartTime=document.getElementsByName("shouldStartTime");//应该出发时间
  76.     var shouldEndTime=document.getElementsByName("shouldEndTime");//应该到达时间
  77.     
  78.     for(var i=0;i<cb.length;i++){
  79.         if(cb[i].checked){
  80.             //出发时间=到达时间-行军时间
  81.             var marchTimeTemp=strToSec(marchTime[i].value);//行军时间
  82.             var preferentTimeTemp=checkNaN(parseFloat(preferentTime[i].value));//优先时间出发
  83.             var startTime=arriveTime-marchTimeTemp;
  84.             //应出发时间=出发时间-优先时间
  85.             shouldStartTime[i].value=secToDate(startTime-preferentTimeTemp);
  86.             //应到达时间=到达时间-优先时间
  87.             shouldEndTime[i].value=secToDate(arriveTime-preferentTimeTemp);
  88.         }   
  89.     }   
  90. }
  91. /*得到最大行军时间*/
  92. function getMaxMarchTime(){
  93.     var cb=document.getElementsByName("cb");
  94.     var marchTime=document.getElementsByName("marchTime");//行军时间
  95.     //var preferentTime=document.getElementsByName("preferentTime");//兵力优先时间(秒)
  96.     //var shouldStartTime=document.getElementsByName("shouldStartTime");//应该出发时间
  97.     //var shouldEndTime=document.getElementsByName("shouldEndTime");//应该到达时间
  98.     var maxMarchTime=0;//最大耗时(秒)=最大优先时间+准备时间+最大行军时间
  99.     for(var i=0;i<cb.length;i++){
  100.         if(cb[i].checked){
  101.             var mt=strToSec(marchTime[i].value);
  102.             if(maxMarchTime<mt){
  103.                 maxMarchTime=mt;
  104.             }
  105.         }   
  106.     }
  107.     return maxMarchTime;
  108. }
  109. /*得到最大优先时间*/
  110. function getMaxPreferentTime(){
  111.     var cb=document.getElementsByName("cb");
  112.     //var marchTime=document.getElementsByName("marchTime");//行军时间
  113.     var preferentTime=document.getElementsByName("preferentTime");//兵力优先时间(秒)
  114.     //var shouldStartTime=document.getElementsByName("shouldStartTime");//应该出发时间
  115.     //var shouldEndTime=document.getElementsByName("shouldEndTime");//应该到达时间
  116.     var maxPreferentTime=0;//最大耗时(秒)=最大优先时间+准备时间+最大行军时间
  117.     for(var i=0;i<cb.length;i++){
  118.         if(cb[i].checked){
  119.             var mt=parseFloat(preferentTime[i].value);
  120.             if(maxPreferentTime<mt){
  121.                 maxPreferentTime=mt;
  122.             }
  123.         }   
  124.     }
  125.     return maxPreferentTime;
  126. }
  127. //alert(strToSec("1:1:1"))
  128. /*时间转换秒*/
  129. function strToSec(str){
  130.     var t=str.split(":");
  131.     var h=parseFloat(t[0]);
  132.     var m=parseFloat(t[1]);
  133.     var s=parseFloat(t[2]);
  134.     return h*3600+m*60+s;
  135. }
  136. function secToDate(sec){
  137.     var d=new Date(sec*1000);
  138.     var s=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate()+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
  139.     return s;
  140. }
  141. /*添加成员*/
  142. function addUser(){
  143.     var a = '   <tr> '
  144.         +'     <td><label> '
  145.         +'       <input type="checkbox" name="cb" value="" checked="checked" class="w2"/> '
  146.         +'     </label></td> '
  147.         +'     <td><input type="text" name="userName" class="w1"/></td> '
  148.         +'     <td><input type="text" name="marchTime" class="w5"/></td> '
  149.         +'     <td><input type="text" name="preferentTime"  class="w2"/></td> '
  150.         +'     <td><input type="text" name="shouldStartTime" class="w3"/></td> '
  151.         +'     <td><input type="text" name="shouldEndTime" class="w3" /></td> '
  152.         +'     <td> '
  153.         +'       <input type="submit" name="Submit3" value="删除" class="bw" οnclick="deleteUser(this.parentNode.parentNode)"/> '
  154.         +'     </td> '
  155.         +'   </tr> ';
  156.     //var templ=new Template(a);
  157.     new Insertion.Bottom('table5', a);
  158.     //alert(templ.evaluate(datas));
  159.     //new Insertion.Bottom('table5', templ.evaluate(datas));
  160. }
  161. function deleteUser(id){
  162.     $('table5').removeChild($(id));
  163. }
  164. function DateDemo(){
  165.    var d, s = "Today's date is: ";           // 声明变量。
  166.    d = new Date();                           // 创建 Date 对象。
  167.    s += (d.getMonth() + 1) + "/";            // 获取月份。
  168.    s += d.getDate() + "/";                   // 获取日。
  169.    s += d.getYear();                         // 获取年份。
  170.    //return d.getTime();
  171.    //return(d);                                // 返回日期。toString()
  172.    //return new Date(1216450850510).toLocaleString();
  173.    //ar ds=1216450850510;
  174.    var ds=1000;
  175.    return new Date(ds).toString();
  176. }
  177. function checkNaN(value){
  178.     if(value){
  179.         return value;
  180.     }
  181.     return 0;
  182. }
  183. var secStep=10;//每次加/减的单位为10秒
  184. /**
  185.     加秒数
  186. */
  187. function plusSec(){
  188.     var readyTime=checkNaN(parseFloat($('readyTime').value));//准备时间
  189.     $('readyTime').value=readyTime+secStep;
  190.     cal();
  191. }
  192. /**
  193.     减秒数
  194. */
  195. function subSec(){
  196.     var readyTime=checkNaN(parseFloat($('readyTime').value));//准备时间
  197.     $('readyTime').value=readyTime-secStep;
  198.     cal();
  199. }
  200. /**cleanT*/
  201. function cleanT(t){
  202.     $(t).value='';
  203.     $(t).focus();
  204. }
  205. function dateConvert(str) 
  206.     if(typeof str!="string"return null
  207.     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 
  208.     var newdate=new Date(); 
  209.     if(dt==nullreturn null
  210.     var y,m,d; 
  211.     y=parseInt(dt[1],10); 
  212.     m=parseInt(dt[2],10); 
  213.     d=parseInt(dt[3],10); 
  214.     var hh,mm,ss;
  215.     hh=parseInt(dt[4]); 
  216.     mm=parseInt(dt[5]); 
  217.     ss=parseInt(dt[6]); 
  218.     //alert(hh+":"+mm+":"+ss)
  219.     if(m>12 || m<0)return null
  220.     if(d>0) { 
  221.         newdate.setFullYear(y); 
  222.         newdate.setDate(d); 
  223.         newdate.setMonth(m-1); 
  224.         
  225.         newdate.setHours(hh);
  226.         newdate.setMinutes(mm);
  227.         newdate.setSeconds(ss);
  228.         return newdate ; 
  229.     }else
  230.         return null
  231.     } 
  232. }
  233. //alert(secToDate(parseInt(dateConvert('2008-10-14 10:57:12').getTime())/1000))
  234. //alert(dateConvert('2008-10-14 10:57:12').getTime())
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值