var searchTag = "0"; //0搜产品,1搜公司 $(function () { //如果是公司搜索,初始化 searchTag值为 1 $(".search-top a").removeClass("active"); if (location.href.toLowerCase().indexOf("/companylist") > 0) { searchTag = 1; } $(".search-top a").each(function () { if (location.href.toLowerCase().indexOf("/companylist") > 0) { if ($(this).attr("tag") == 1) { $(this).addClass("active"); $(".search-top i").css("left", "64px"); } } else if (location.href.toLowerCase().indexOf("/productslist") > 0) { if ($(this).attr("tag") == 0) { $(this).addClass("active"); $(".search-top i").css("left", "16px"); } } }); $(".search-top a").on("click", function () { searchTag = $(this).attr("tag"); $(this).addClass("active").siblings().removeClass("active"); if ($(".search-top i").css("left") == '16px') { $(".search-top i").css("left", "64px"); } else { $(".search-top i").css("left", "16px"); } }) var item = $(".s_nav_item ul"); for (var i = 0; i < item.length; i++) { if (item.eq(i).height() == 45) { item.eq(i).next("em").hide() } } $(".s_nav_item em").on("click", function () { if ($(this).hasClass("up")) { $(this).removeClass("up").parent(".s_nav_item").css("height", "45") } else { $(this).addClass("up").parent(".s_nav_item").css("height", "auto") } }) $("#btnSearch").click(function () { clickSearch(); }); $("#txtkey").bind('keydown', function (e) { var key = e.which; if (key == 13) { clickSearch(); } }); }) function clickSearch() { var key = $.trim($("#txtkey").val()); if (key == '') { alert("请输入要搜索的关键词"); return; } var s_url = ""; switch (parseInt(searchTag)) { case 1: s_url = "/CompanyList/all/0000.html?q=" + encodeURI(key); break; case 0: s_url = "/ProductsList/all/0000.html?q=" + encodeURI(key); break; default: s_url = "/ProductsList/all/0000.html?q=" + encodeURI(key); break; } location.href="t_vsm;" }