top_search.js
1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* @description top_seatch on diligrp-website
*
* @author <a href="mailto:akhuting@hotmail.com">Alex Yang</a>
* @date 2014年06月24日 17:29
*/
$(function () {
$(".sear-li").bind("click", function () {
var i = $(this).text();
var s = $(".sear-d").text();
var t = $(this).attr("data-searchtype");
var k = $(".sear-d").attr("data-searchtype");
$(".sear-d").text(i).attr("data-searchtype", t);
$(".sear-li").text(s).attr("data-searchtype", k);
$(".sea-tab-ul2").hide();
});// 搜索下拉+点击切换文字
$("#autocomplete").attr("placeholder", search.keywords[(Math.ceil(Math.random() * 2) - 1)]);
// 搜索框智能提示
$('#autocomplete').autocomplete({
serviceUrl: DiliPath.homePath + "tip.html",
paramName: "key",
dataType: "jsonp",
appendTo: ".mo-fn2 span.sp5",
triggerSelectOnValidInput: false,
onSelect: function (suggestion) {
search.topSearch();
}
});
$("#autocomplete").keypress(function (event) {
if (event.which == 13) {
search.topSearch();
}
});
$("#search").click(function () {
search.topSearch();
});
});
var search = {
// top search function
topSearch: function () {
var keyword = $("#autocomplete").val();
keyword = $.trim(keyword);
keyword = encodeURIComponent(keyword);
if (jQuery.trim(keyword) == "") {
var def = $("#autocomplete").attr("placeholder");
keyword = def.substring(2, def.indexOf("”"));
}
var searchtype = $(".sear-d").attr("data-searchtype");
window.location.href = DiliPath.homePath + "search.html?" + searchtype
+ "=&key=" + keyword;
},
keywords: ["搜“黄瓜”试试,大黄瓜小黄瓜应有尽有", "搜“四川”试试,保证多快好省"]
};