/*删除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 = "