-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.js
executable file
·41 lines (41 loc) · 1.11 KB
/
search.js
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
/**
* 搜索
*/
var searchByKw = (function(){
var s_dom = 0;
var s_url = '([$search_base_url])';
var G = function (val, dom) {
dom = typeof(dom) == 'object' ? dom : window.document;
return dom.getElementById(val);
}
var bind = function(obj, type, fn) {
if (obj.attachEvent) {
obj['e'+type+fn] = fn;
obj[type+fn] = function(){obj['e'+type+fn](window.event)}
obj.attachEvent('on'+type, obj[type+fn]);
} else {
obj.addEventListener(type, fn, false);
}
}
var search = function() {
if (s_dom == 0) {
s_dom = G('search_keyword');
}
var val = s_dom.value;
if (val != '关键字' && val != '') {
window.open(s_url + encodeURIComponent(val));
} else {
alert('请输入关键字!');
s_dom.focus();
}
}
if (s_dom == 0) {
s_dom = G('search_keyword');
}
bind(s_dom, 'keypress', function(evt){
if (evt.keyCode == 13) {
search();
}
});
return {run:search, G:G, bind:bind}
})();