//各个函数区 //Obj 单击对像,calback回调函数 function TrunMenu2(Obj,callback){ $(Obj).siblings("li").removeClass("active").end().addClass("active"); var cmid = $(Obj).attr("mid"); var data = $(Obj).attr("data").split("|"); if($("#"+cmid).size()<1){ $("#waitingtable").siblings("table:visible,div:visible").hide().end().show(); $.ajax({ url:'/api/api.asp?method=cht.flight.deals&C1='+data[0]+'&id='+cmid+'&city='+data[1], success:function(data){ $("#waitingtable").hide(); $("#CheapChinaFlights").append(data); $("#"+cmid).siblings("table:visible,div:visible").hide().end().show(); if(typeof callback =="function"){ callback(Obj); } } }); } else { $("#"+cmid).siblings("table:visible,div:visible").hide().end().show(); if(typeof callback =="function"){ callback(Obj); } } } function TrunMenu3(Obj,callback){ $(Obj).siblings("li").each(function(){ var NewCls = $(this).attr("class").replace("active",""); $(this).attr("class",NewCls); }).end().attr("class",function(){ return $(this).attr("class").replace("active","")+"active"; }); var Objmidvar = $(Obj).attr("mid"); $("#"+Objmidvar).siblings("table:visible,div:visible").hide().end().show(); $(".flightAds span").hide(); switch(Objmidvar){ case "chinaSearch"://国内机票 $("#flightAds_1").show(); break; case "HMSearch": //港澳机票 $("#flightAds_2").show(); break; case "InterSearch": //国际机票 $("#flightAds_3").show(); break; } //var _callback = callback; if(typeof callback =="function"){ callback(Obj); } } function cb(obj){ $(obj).append($("#MenuBottomArr")); } function cb2(obj){ $(obj).append($("#MenuBottomArr2")); } // 转换为数字 function intval(v) { v = parseInt(v); return isNaN(v) ? 0 : v; } // 获取元素信息 function getPos(e) { var l = 0; var t = 0; var w = intval(e.style.width); var h = intval(e.style.height); var wb = e.offsetWidth; var hb = e.offsetHeight; while (e.offsetParent){ l += e.offsetLeft + (e.currentStyle?intval(e.currentStyle.borderLeftWidth):0); t += e.offsetTop + (e.currentStyle?intval(e.currentStyle.borderTopWidth):0); e = e.offsetParent; } l += e.offsetLeft + (e.currentStyle?intval(e.currentStyle.borderLeftWidth):0); t += e.offsetTop + (e.currentStyle?intval(e.currentStyle.borderTopWidth):0); return {x:l, y:t, w:w, h:h, wb:wb, hb:hb}; } // 获取滚动条信息 function getScroll() { var t, l, w, h; if (document.documentElement && document.documentElement.scrollTop) { t = document.documentElement.scrollTop; l = document.documentElement.scrollLeft; w = document.documentElement.scrollWidth; h = document.documentElement.scrollHeight; } else if (document.body) { t = document.body.scrollTop; l = document.body.scrollLeft; w = document.body.scrollWidth; h = document.body.scrollHeight; } return { t: t, l: l, w: w, h: h }; } // 锚点(Anchor)间平滑跳转 function scroller(el, duration) { if(typeof el != 'object') { el = document.getElementById(el); } if(!el) return; var z = this; z.el = el; z.p = getPos(el); z.s = getScroll(); z.clear = function(){window.clearInterval(z.timer);z.timer=null}; z.t=(new Date).getTime(); z.step = function(){ var t = (new Date).getTime(); var p = (t - z.t) / duration; if (t >= duration + z.t) { z.clear(); window.setTimeout(function(){z.scroll(z.p.y, z.p.x)},13); } else { st = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.y-z.s.t) + z.s.t; sl = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.x-z.s.l) + z.s.l; z.scroll(st, sl); } }; z.scroll = function (t, l){window.scrollTo(l, t)}; z.timer = window.setInterval(function(){z.step();},13); window.setTimeout(function(){$("#airlineSearch li").eq(2).trigger('click')},duration); } $(function(){ //价格提示 setdateobj('takeoffDate1',3); setdateobj('takeoffDate2',6); setdateobj('departureDate',3); setdateobj('returnDate',6); //日历 var sdates = $("#takeoffDate1,#departureDate").datepicker({showAnim:"fadeIn",duration:0,minDate: 0, maxDate:"1y",numberOfMonths: 2,showButtonPanel: true}).bind('dateSelected', function(e, selectedDate, td){ switch($(this).attr("id")){ case "takeoffDate1": if($("#chinaSearch :radio[checked]").val() == '2'){ $(sdates2[0]).datepicker('option', 'minDate', new Date(selectedDate)).focus(); } break; case "departureDate": if($("#HMSearch :radio[checked]").val() == 'roundtrip'){ $(sdates2[1]).datepicker('option', 'minDate', new Date(selectedDate)).focus(); } break; default: } } ); var sdates2= $("#takeoffDate2,#returnDate") .datepicker({showAnim:"fadeIn",duration:0,minDate: 0, maxDate:"1y",numberOfMonths: 2,showButtonPanel: true}); //往返选择 $("input[name=triptype]").click(function(){ switch($(this).val()){ case "1": //单程 $(this).parents("form").find("#endDate").hide(); break; case "2": //往返 $(this).parents("form").find("#endDate").show(); break; } }); //港澳机票 $(':radio[name=flytype]').click(function(){ switch($(this).val()){ case "oneway": //单程 $("#HMSearch #endDate").hide(); break; case "roundtrip": //往返 $("#HMSearch #endDate").show(); break; } }); $("#chinaSearch [name=startCode1],#HMSearch [name=startCode1]").change(function(){ var chObj = $("#CheapChinaFlights .topFlightDeals li"); switch($(this).val()){ case "PEK":chObj.eq(0).trigger("click");break; case "SHA":chObj.eq(1).trigger("click");break; case "CAN":chObj.eq(2).trigger("click");break; case "SZX":chObj.eq(3).trigger("click");break; case "XIY":chObj.eq(4).trigger("click");break; case "KWL":chObj.eq(5).trigger("click");break; case "CTU":chObj.eq(6).trigger("click");break; case "HGH":chObj.eq(7).trigger("click");break; case "TAO":chObj.eq(8).trigger("click");break; default:chObj.eq(0).trigger("click");break; } }); $.ajax({ url:'/api/api.asp?method=cht.flight.deals&C1=pek&id=chtCheep_Beijing&city=beijing', success:function(data){ $("#waitingtable").hide(); $("#CheapChinaFlights").append(data); } }); });