/** +---------------------------------------------------------- * 下拉菜单 +---------------------------------------------------------- */ $(function() { /* 主导航 */ $("#mainnav ul li").hover(function() { $(this).addclass("hover"); $('ul:first', this).css('display', 'block'); }, function() { $(this).removeclass("hover"); $('ul:first', this).css('display', 'none'); }); /* 顶部导航 */ $("ul.topnav li.parent").hover(function() { $(this).addclass("hover"); $('ul:first', this).css('display', 'block'); }, function() { $(this).removeclass("hover"); $('ul:first', this).css('display', 'none'); }); }); /** +---------------------------------------------------------- * 刷新验证码 +---------------------------------------------------------- */ function refreshimage() { var cap = document.getelementbyid("vcode"); cap.src = cap.src + '?'; } /** +---------------------------------------------------------- * 搜索框的鼠标交互事件 +---------------------------------------------------------- */ function formclick(name, text) { var obj = name; if (typeof(name) == "string") obj = document.getelementbyid(id); if (obj.value == text) { obj.value = ""; } obj.onblur = function() { if (obj.value == "") { obj.value = text; } } } /** +---------------------------------------------------------- * 更新购物车数量 +---------------------------------------------------------- */ function changenumber(product_id, calculate, root_url) { var item_id = document.getelementbyid("number_" + product_id); if (calculate == 'add') { item_id.value++; } else { if (item_id.value > 1) { item_id.value--; } } changeprice(product_id, item_id.value, root_url); } /** +---------------------------------------------------------- * 更新购物车价格 +---------------------------------------------------------- */ function changeprice(product_id, number, root_url) { if (number == 0) { document.getelementbyid("number_" + product_id).value = 1; var number = 1; } $.ajax({ type: "post", url: root_url + 'order.php?rec=update', data: {"product_id":product_id, "number":number}, datatype: "json", success: function(order) { $("#subtotal_" + product_id).html(order.subtotal); $("#total").html(order.total); $("#product_amount").html(order.product_amount); } }); } /** +---------------------------------------------------------- * 更新快递费 +---------------------------------------------------------- */ function changeshipping(unique_id, root_url) { $.ajax({ type: "post", url: root_url + 'order.php?rec=change_shipping', data: {"unique_id":unique_id}, datatype: "json", success: function(order) { $("#shipping_fee").html(order.shipping_fee); $(".order_amount").html(order.order_amount) } }); } /** +---------------------------------------------------------- * 表单提交 +---------------------------------------------------------- */ function dousubmit(form_id) { var formparam = $("#"+form_id).serialize(); //序列化表格内容为字符串 $.ajax({ type: "post", url: $("#"+form_id).attr("action")+'&do=callback', data: formparam, datatype: "json", success: function(form) { if (!form) { $("#"+form_id).submit(); } else { for(var key in form) { $("#"+key).html(form[key]); } } } }); } /** +---------------------------------------------------------- * 弹出窗口 +---------------------------------------------------------- */ function doubox(page) { $.ajax({ type: "get", url: page, data: "if_check=1", datatype: "html", success: function(html) { $(document.body).append(html); } }); } /** +---------------------------------------------------------- * 清空对象内html +---------------------------------------------------------- */ function douremove(target) { var obj = document.getelementbyid(target); obj.parentnode.removechild(obj); } /** +---------------------------------------------------------- * 收藏本站 +---------------------------------------------------------- */ function addfavorite(url, title) { try { window.external.addfavorite(url, title) } catch(e) { try { window.sidebar.addpanel(title, url, "") } catch(e) { alert("加入收藏失败,请使用ctrl+d进行添加") } } } /** +---------------------------------------------------------- * 在线客服 +---------------------------------------------------------- */ $(document).ready(function(e) { // 右侧滚动 $("#onlineservice").css("right", "0px"); // 弹出窗口 var button_toggle = true; $(".onlineicon").live("mouseover", function() { button_toggle = false; $("#pop").show(); }).live("mouseout", function() { button_toggle = true; hiderighttip() }); $("#pop").live("mouseover", function() { button_toggle = false; $(this).show() }).live("mouseout", function() { button_toggle = true; hiderighttip() }); function hiderighttip() { settimeout(function() { if (button_toggle) $("#pop").hide() }, 500) } // 返回顶部 $(".gotop").live("click", function() { var _this = $(this); $('html,body').animate({ scrolltop: 0 }, 500, function() { _this.hide() }) }); $(window).scroll(function() { var htmltop = $(document).scrolltop(); if (htmltop > 0) { $(".gotop").show() } else { $(".gotop").hide() } }) });