help-search.js
1.48 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
/**
* [帮助中心 搜索]
* @author: wsl(shuiling.wang@yoho.cn)
* @date: 2016/12/02
*/
var helpSearch = {
$search: $('.help-search'),
init: function() {
var _this = this;
var $helpSearchForm = $('#help-search-form');
var $searchBtn = $('.search-btn');
_this.searchDefaultVal();
$searchBtn.click(function() {
if (_this.$search.val() === '请输入您想知道的帮助信息') {
_this.$search.val('');
}
$helpSearchForm.submit();
});
_this.$search.keyup(function(e) {
var key = $(this).val();
if (key === '请输入您想知道的帮助信息') {
$(this).val('');
}
if (e.which === 13) {
if (key) {
$helpSearchForm.submit();
}
}
});
},
searchDefaultVal: function() {
var _this = this;
var defaultVal = '请输入您想知道的帮助信息';
_this.$search.focus(function() {
var key = _this.$search.val();
if (key === defaultVal) {
_this.$search.val('').css('color', '#1b1b1b');
}
}).blur(function() {
var key = _this.$search.val();
if ($.trim(key) === '') {
_this.$search.val(defaultVal).css('color', '#989898');
}
}).val(defaultVal).css('color', '#989898');
}
};
module.exports = helpSearch;