/*删除url参数*/ function DelUrlParams(names) { if(typeof(names) == 'string') { names = [names]; } var loca = window.location; var obj_url = {}; var arr = loca.search.substr(1).split("&"); //获取参数转换为object for(var i = 0; i < arr.length; i++) { arr[i] = arr[i].split("="); if(arr[i].length == 2) { obj_url[arr[i][0]] = arr[i][1]; } }; //删除指定参数 for(var i = 0; i < names.length; i++) { delete obj_url[names[i]]; } //重新拼接url var url = loca.origin + loca.pathname + "?" + JSON.stringify(obj_url).replace(/[\"\{\}]/g, "").replace(/\:/g, "=").replace(/\,/g, "&"); try { window.history.replaceState(null, null, url); //替换地址栏 } catch(err) {} } /*改变url参数值*/ function ChangeUrlStatic(name, value) { var url = window.location.href; var reg = eval('/([\?|&|#]' + name + '=)[^&|^#]*/gi'); value = value.toString().replace(/(^\s*)|(\s*$)/g, ""); //移除首尾空格 var url2 = url; if(!value) { url2 = url.replace(reg, ''); //正则替换 } else { if(url.match(reg)) { url2 = url.replace(reg, '$1' + value); //正则替换 } else { url2 = url + (url.indexOf('?') > -1 ? '&' : '?') + name + '=' + value; //没有参数添加参数 } } try { window.history.replaceState(null, null, url2); //替换地址栏 } catch(err) {} } /*加入收藏 加入收藏*/ function AddFavorite(sURL, sTitle) { try { window.external.addFavorite(sURL, sTitle); } catch(e) { try { window.sidebar.addPanel(sTitle, sURL, ""); } catch(e) { alert("加入收藏失败,请使用Ctrl+D进行添加"); } } } /*设为首页 设为首页*/ function SetHome(obj, vrl) { try { obj.style.behavior = 'url(#default#homepage)'; obj.setHomePage(vrl); } catch(e) { if(window.netscape) { try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); } catch(e) { alert("此操作被浏览器拒绝!\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。"); } var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch); prefs.setCharPref('browser.startup.homepage', vrl); } } } //复制链接 function copyUrl(url) { var str = url; /*复制操作*/ var oInput = document.createElement('input'); oInput.value = str; document.body.appendChild(oInput); oInput.select(); document.execCommand("Copy"); oInput.style.display = 'none'; document.body.removeChild(oInput); alert("复制成功!"); } /*滚动*/ function startmarquee(lh, speed, delay, height, ID) { var t; var oHeight = height; /** div的高度 **/ var p = false; var o = document.getElementById(ID); var preTop = 0; o.scrollTop = 0; function start() { t = setInterval(scrolling, speed); o.scrollTop += 1; } function scrolling() { if(o.scrollTop % lh != 0 && o.scrollTop % (o.scrollHeight - oHeight - 5) != 0) { preTop = o.scrollTop; o.scrollTop += 1; if(preTop >= o.scrollHeight || preTop == o.scrollTop) { o.scrollTop = 0; } } else { clearInterval(t); setTimeout(start, delay); } } setTimeout(start, delay); } /*获取元素的位置*/ function getPosition(element) { var actualLeft = element.offsetLeft, actualTop = element.offsetTop, current = element.offsetParent; // 一直循环直到根元素 while(current !== null) { actualLeft += current.offsetLeft; actualTop += current.offsetTop; current = current.offsetParent; } // 返回包含left、top坐标的对象 return actualTop; } /*改变颜色*/ var changeC; var colNum = 0; function changeColour() { colNum = 0; if(changeC) { window.clearInterval(changeC); } changeC = window.setInterval(function somefunction() { colNum++; if(colNum % 2 == 0) { $(".personmod").css("box-shadow", "0 0px 5px #ff8800"); } else { $(".personmod").css("box-shadow", "0 0px 5px #ddd"); } if(colNum == 20) { /*限制次数*/ window.clearInterval(changeC); $(".personmod").css("box-shadow", "0 3px 5px #ddd"); } }, 100); /*取消颜色变换*/ $(".personmod").hover(function() { }, function() { window.clearInterval(changeC); $(".personmod").css("box-shadow", "0 3px 5px #ddd"); }); } var Mail = new function() { this.Email = function() { $("#EmailDiv").css("display", ""); } this.SendEmail = function() { var emailval = $("#email").val(); if(emailval == "请输入你的邮箱地址!" || emailval == "") { alert("请输入你的邮箱地址!"); $("#email").focus(); return; } var x = Math.random() * 10; var url = "?action=SendMain&Email=" + escape(emailval) + "&title=" + escape($("#Subject").val()) + "&" + x; $.get(url, function(obj) { GetSendEmailBlock(obj); }); } var GetSendEmailBlock = function(obj) { if(obj == "True") { alert("邮件已经发送,请查收。"); } else if(obj == "err") { alert("邮件发送失败,请稍后再试!"); } else { alert("邮件发送失败:" + obj); } } } var MyNav = new function() { $myNav = $("#myNav"); var defaultShow = true; var $aside = $myNav.children(".aside"); if($aside.css("display") == "none") { defaultShow = false; } if(!defaultShow) { $myNav.hover(function() { $aside.show(); }, function() { $aside.hide(); }); } $aside.children(".item").hover(function() { var $this = $(this); $this.addClass("hover"); var $menu = $this.children(".f_menu"); $menu.show(); }, function() { var $this = $(this); $this.removeClass("hover"); var $menu = $this.children(".f_menu") $menu.hide(); }); } var Scroll = function(st, callBack) { $("html").animate({ scrollTop: st }, "slow", callBack); $("body").animate({ scrollTop: st }, "slow", callBack); } var Search = new function() { var obj = this; obj.startCity = ""; obj.SearchLines = function() { var $input = $(".ss .input input"); var st = $input.val(); st = st.replace(/\s/, ""); if(st == "") { alert("请输入景点名称或线路编号!"); $input.focus(); return; } var patrn = /^[^`~!@#$%^&*()+=|\\\][\]\{\}:;'\,.<>/?]{1}[^`~!@$%^&()+=|\\\][\]\{\}:;'\,.<>?]{0,19}$/; if(!patrn.exec(st) && (st != "")) { alert("关键字包含非法字符"); return; } var pageUrl = "/xianlu/"; if(obj.startCity != "") { pageUrl = "/" + obj.startCity + pageUrl } patrn = /^((\d{1,9})|(zd\d{1,9}))$/ig; if(patrn.exec(st)) //根据ID直接查询 { st = st.replace(/zd/ig, ""); pageUrl = "/xianlu/" + st; } else { pageUrl = pageUrl + "?kw=" + encodeURIComponent(st) } //统计 var url = "/xianlu/" + "?a=tongji&kw=" + st + "&" + Math.random(); var reg = /^\d+$/; $.get(url, function(data) { if(reg.exec(data)) { if(pageUrl.indexOf('?') > -1) { location = pageUrl + "&SearchID=" + data; } else { location = pageUrl + "?SearchID=" + data; } } else { location = pageUrl } }); } $(".ss .sub").click(obj.SearchLines); } //搜索提示 var SearchClue = new function() { searchClueTag = true; var obj = this; var name = arguments[0]; var $searchClueDiv = null; var $keyWordInput = $(".ss .input input"); var nowJson = null; var nowPage = 0; var pageSize = 8; var isClickDiv = false; var timeerID; var selectIndex = -1; obj.KeyUp = function(e) { var key = window.event ? e.keyCode : e.which; if((key >= 38 && key <= 40) || (key == 13)) { return; } var kw = $keyWordInput.val().replace(/(\s)|(请输入景点名称)/ig, ""); var reg = /^[\u4e00-\u9fa5a-zA-Z]+$/; if(reg.test(kw)) { window.clearTimeout(timeerID); timeerID = window.setTimeout(function() { var url = "/inc/SearchClue.ashx?keyword=" + escape(kw); $.getJSON(url, obj.Show_CallBack); }, 300); } else { obj.Hide(); } }; obj.KeyDown = function(e) { var key = window.event ? e.keyCode : e.which; if(key == 13) { if(selectIndex == -1) { Search.SearchLines(); } else { $searchClueDiv.find("ul:eq(0) li").eq(selectIndex).click(); } return false; } if(key != 38 && key != 40) { return; } var $lis = $searchClueDiv.find("ul:eq(0)").find("li"); var num = $lis.size(); if(num == 0) { return; } if(key == 38) { if(selectIndex > -1) { selectIndex--; } else { selectIndex = num - 1; } } else { if(selectIndex < (num - 1)) { selectIndex++; } else { selectIndex = -1; } } $lis.css("background", ""); $lis.eq(selectIndex).css("background", "#D8EDFC"); // $lis.removeClass("hover"); //$lis.eq(selectIndex).addClass("hover"); }; obj.Hide = function() { $searchClueDiv.html(""); $searchClueDiv.hide(); }; obj.Show_CallBack = function(json) { if(json.length > 0) { nowJson = json; obj.ShowPage(1); } else { obj.Hide(); } }; obj.SearchTongJi = function(SearchKey) { var url = "/xianlu/" + "?a=tongji&kw=" + SearchKey + "&" + Math.random(); $.get(url, function(data) {}); }; obj.ShowPage = function(page) { selectIndex = -1; nowPage = page; var temStr = "
"; if(nowJson.length > pageSize) { temStr += "
"; for(var j = 0; j < nowJson.length / pageSize; j++) { if((j + 1) == page) temStr += " " + (j + 1) + ""; else temStr += " " + (j + 1) + " "; } temStr += "
"; } temStr += "
"; $searchClueDiv.html(temStr); $searchClueDiv.show(); $searchClueDiv.find("iframe").css("height", ($searchClueDiv.height()) + "px"); $keyWordInput.focus(); }; var $keyWordInput = $(".ss .input input"); if($keyWordInput.size() > 0) { $keyWordInput.parent().css({ "position": "relative", "z-index": "50" }); var position = $keyWordInput.position(); $keyWordInput.parent().append("
"); var $searchClueDiv = $("#searchClueDiv"); $searchClueDiv.css({ "top": $keyWordInput.outerHeight() + position.top, "width": $keyWordInput.outerWidth() - 2 }); $keyWordInput.keydown(obj.KeyDown).keyup(obj.KeyUp); //.focus(function(e){isClickDiv=true;obj.KeyUp(e);}); $searchClueDiv.click(function() { isClickDiv = true; }); $("body").click(function() { if(!isClickDiv) { obj.Hide(); } else { isClickDiv = false; } }); } } //留言 var GuestBook = new function() { var obj = this; var s___c = ""; obj.SaveConsult = function() { var patrn = /<[a-zA-Z][a-zA-Z0-9]*>/; var GuestName = $("#consult input[name='Name']") if(GuestName.val() == "") { alert("请输入姓名。"); GuestName.focus(); return; } if(patrn.exec(GuestName.val()) && (GuestName.val() != "")) { alert("姓名包含非法字符。"); GuestName.focus(); return; } var GuestMoble = $("#consult input[name='Moble']"); var GuestMail = $("#consult input[name='Mail']"); if(GuestMoble.val()=="" && GuestMail.val()==""){ alert("请输入联系电话或邮箱。"); return; } var regMoble = /^1[3|4|5|7|8][0-9]{9}$/; var reg = /^\d{11}$/ if(GuestMoble.val()!="" && !reg.exec(GuestMoble.val())) { alert("请输入有效联系电话。"); GuestMoble.focus(); return; } /* if(!reg.exec(GuestMoble.val())) { alert("电话号码格式:15988888888,11位的数字"); GuestMoble.focus(); return; } if(GuestMail.val() == GuestMail.get(0).defaultValue) { GuestMail.val(""); } */ var Content = $("#consult textarea[name='Content']"); if(Content.val() == "") { alert("请输入咨询内容。"); Content.focus(); return; } if(patrn.exec(Content.val()) && (Content.val() != "")) { alert("咨询内容包含非法字符。"); Content.focus(); return; } var $CC = $("#consult input[name='CC']"); if(typeof $CC != "undefined") { if($CC.val() == "") { alert("请输入正确的验证码!"); $CC.focus(); return; } } var c = $("#consult").serialize(); if(c == s___c) { alert("请不要重复咨询"); return; } /*提交留言*/ $.post("/guestbook/g0.html", c, function(data) { if(data == "True") { alert("留言提交成功,我们会尽快回复!"); $("#consult input[type='text'],#consult textarea").val(''); } else if(data == "ccerr") { alert('验证码错误,请重新输入!'); } else { alert(data); } if(typeof $CC != "undefined") { $CC.val(""); $CC.focus(); $('#consult #gbCheckImg').click(); } }); s___c = c; }; obj.UpdateHits = function () { var purl = window.location.href; var post_data = { a: 'hits' }; $.post(purl, post_data, function (rdata) { //console.log(rdata); }); }; }; /*文章*/ var ArticleObj = new function () { var obj = this; /*浏览量*/ obj.UpdateHits = function () { var purl = window.location.href; var post_data = { a: 'hits' }; $.post(purl, post_data, function (rdata) { //console.log(rdata); }); }; }; //tab切换开始 function Tab(titleID) { var obj = this; var contentID = titleID, titleCss = "_tabtitle", contentCss = "_tabcontent"; if(arguments.length >= 2) { contentID = arguments[1]; } if(arguments.length >= 3) { titleCss = arguments[2]; } if(arguments.length >= 4) { contentCss = arguments[3]; } var $titleID = $("#" + titleID); var $contentID = $("#" + contentID); var $titles = $titleID.find("." + titleCss); var $contents = $contentID.find("." + contentCss); if($titles.size() != $contents.size()) { return; } obj.Start = function() { var e = (arguments.length >= 1) ? arguments[0] : "mouseenter"; if(e == "mouseenter") { $titles.mouseenter(function() { obj.Select(this); }); } if(e == "mouseover") { $titles.mouseover(function() { obj.Select(this); }); } else if(e == "click") { $titles.click(function() { obj.Select(this); }); } } obj.nowSelect = null; obj.Select = function(select) { if(obj.nowSelect != select) { obj.nowSelect = select; var index = $titles.index(select); $titles.removeClass("on"); $(select).addClass("on"); $contents.hide().eq(index).show(); if($contents.eq(index).find("img.lazy")) { setTimeout(function() { $contents.eq(index).find("img.lazy").trigger("scroll"); }, 100); } } }; }; function getCookie(name) { var strCookie = document.cookie; var arrCookie = strCookie.split("; "); for(var i = 0; i < arrCookie.length; i++) { var arr = arrCookie[i].split("="); if(arr[0] == name) return decodeURIComponent(arr[1]); } return ""; } function MyTongJi(typeCode, categoryCode, id) { var url = "/tongji?typeCode=" + typeCode + "&categoryCode=" + categoryCode + "&id=" + id; $.get(url, function(data) {}); } //ajax加载状态 function ShowUpdateProgresDiv() { $("body").append(''); window.setInterval("SetDivMiddle('UpdateProgresDiv')", 1500); $(document).ajaxStart(function() { console.log("ajaxStart()"); $("#UpdateProgresDiv").show(); }).ajaxStop(function() { console.log("ajaxStop()"); $("#UpdateProgresDiv").hide(); }); } //全区域居中 function SetDivMiddle(obj) { var de = document.documentElement; var db = document.body; var viewW = de.clientWidth == 0 ? db.clientWidth : de.clientWidth; var viewH = de.clientHeight == 0 ? db.clientHeight : de.clientHeight; var scrollL = de.scrollLeft == 0 ? db.scrollLeft : de.scrollLeft; var scrollT = de.scrollTop == 0 ? db.scrollTop : de.scrollTop; document.getElementById(obj).style.left = (scrollL + (viewW - 70) / 2) + "px"; document.getElementById(obj).style.top = (scrollT + (viewH - 102) / 2) + "px"; } ShowUpdateProgresDiv();