banxitan

统计

留言簿(2)

阅读排行榜

评论排行榜

酒店价格间夜显示(JavaScript 实现)

酒店间夜价格显示实现:

跨周:



<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding
="utf-8"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="javascript" type="text/javascript" src="${pageContext.request.contextPath}/js/My97DatePicker/WdatePicker.js"></script>
<title>Date操作</title>
</head>
<%
    
String startDate = request.getParameter("startDate")==null?"":request.getParameter("startDate");
    
String endDate = request.getParameter("endDate")==null?"":request.getParameter("endDate");
%>
<body>
<form action="date.jsp" name="form1">
Start Date:
<input id="startDate" name="startDate" type="text" onClick="WdatePicker()" value="<%=startDate%>" /> <br/>
End Date:
<input id="endDate" name="endDate" type="text" onClick="WdatePicker()" value="<%=endDate%>" /> <br/>
<input type="submit" value="submit">
</form>
<% 
    
if(!"".equals(startDate.trim()) && !"".equals(endDate.trim())){
    
%>
<script type="text/javascript">
    
var startDate = document.getElementById("startDate").value;
    
var endDate = document.getElementById("endDate").value;
    startDate 
= startDate.replace(/-/g, "/");
    endDate 
= endDate.replace(/-/g, "/");     
    
var s1 = new Date(startDate);
    
var s2 = new Date(endDate);
    
var days= (s2.getTime() - s1.getTime())/86400000;
    
var computerWerk = Math.ceil(days/7);   
    document.write(
"周数="+computerWerk+" days="+days);
</script>
    
<table border="1">
        
<tr>
        
<td>房型</td>
        
<td>门市价</td>
        
<td>早餐</td>
        
<script type="text/javascript">
        
if(computerWerk>1){
            document.write(
"<td>&nbsp;&nbsp;&nbsp;</td>");
        }

         
for(var i=0; i< days && i<7;i++){
            
var myDate=new Date()
            myDate.setDate(s1.getDate()
+i);
            
//if(i>6){
            //        break;
            //    }else{
            document.write("<td>周"+"日一二三四五六".charAt(myDate.getDay())+"</td>");
            
//}
            
        }

        
</script>
        
</tr>
        
<script type="text/javascript">
        
if(computerWerk>1){
            
for(var week=1;week<=computerWerk;week++){
                document.write(
"<tr>");
                
if(week==1){
                    document.write(
"<td rowspan="+(computerWerk+1)+">标准房</td>");
                    document.write(
"<td rowspan="+(computerWerk+1)+">1950</td>");
                    document.write(
"<td rowspan="+(computerWerk+1)+">含早</td>");
                    document.write(
"<td>第"+week+"周</td>");
                    
for(var i=0; i<7;i++){
                        
var myDate=new Date();
                        myDate.setDate(s1.getDate()
+i);
                        
//if(i>6){
                        //        break;
                        //    }else{
                        document.write("<td>"+myDate.toUTCString()+"</td>");
                        
//}
                    }

                }
else{
                    document.write(
"<td>第"+week+"周</td>");
                    
for(var q=0; q<7;q++){
                        
var myDate=new Date();
                        myDate.setDate(s1.getDate()
+((week-1)*7)+q);
                        
//if(q>6){
                        //        break;
                        //    }else{
                                if((week-1)*7+< days){
                                   document.write(
"<td>"+myDate.toUTCString()+"</td>");
                                }
else{
                                   document.write(
"<td>&nbsp;&nbsp;&nbsp;</td>");
                                }

                        
//}
                    }

                    
                }

                document.write(
"</tr>");
            }

         }
else{
         document.write(
"<tr>");
         document.write(
"<td>标准房</td>");
         document.write(
"<td>1950</td>");
         document.write(
"<td>含早</td>");
         
for(var i=0; i<days;i++){
                    
var myDate=new Date();
                    myDate.setDate(s1.getDate()
+i);
                    
if(i>7){
                            
break;
                        }
else{
                    document.write(
"<td>"+myDate.toUTCString()+"</td>");
            }

        }

         document.write(
"</tr>");    
    }

        
</script>
    
</table>
<%
    }
%>
</body>
</html>








posted on 2009-04-21 13:31 MikyTan 阅读(402) 评论(0)  编辑  收藏 所属分类: JavaScript


只有注册用户登录后才能发表评论。


网站导航: