write-search.js
887 Bytes
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
/**
* 将搜索结果存localStorage
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/10/29
*/
var ranToken = ' ??++ ';
//获取分隔符
function getRanToken() {
return ranToken;
}
//绑定提交前的存local操作
function bindWirteLocal($form) {
$form.on('submit', function() {
var query = this.query.value,
historys;
if (localStorage) {
historys = localStorage.getItem('historys');
historys = historys ? historys : '';
if (historys.indexOf(ranToken + query + ranToken) > -1) {
return;
}
if (historys === '') {
query = ranToken + query;
}
historys += query + ranToken;
localStorage.setItem('historys', historys);
}
});
}
exports.getRanToken = getRanToken;
exports.bindWirteLocal = bindWirteLocal;