|
111 | 111 | }
|
112 | 112 | if(arrResultHTML.length === 0){
|
113 | 113 | var myLi = document.createElement("LI");
|
114 |
| - myLi.innerHTML = '<span>'+this.query?'请尝试输入一些字符,进行搜素!'+'</span>':'没有搜索到任何内容,请尝试输入其它字符!'; |
| 114 | + myLi.innerHTML = '<span>'+this.query?'请尝试输入一些字符,进行搜索!'+'</span>':'没有搜索到任何内容,请尝试输入其它字符!'; |
115 | 115 | elm.appendChild(myLi);
|
116 | 116 | }
|
117 | 117 | },
|
|
120 | 120 | var kw = self.getQueryString('kw');
|
121 | 121 | var timer = null
|
122 | 122 | this.elm_query.value = kw;
|
123 |
| - this.query = kw; |
| 123 | + this.query = kw||''; |
124 | 124 | if(this.elm_search_result) self.searchResult(true);
|
125 | 125 | this.bindEvent(this.elm_query,'input',function(e){
|
126 | 126 | self.query = e.target.value;
|
| 127 | + |
127 | 128 | self.pushState()
|
128 |
| - self.searchResult(); |
129 |
| - self.elm_result.style.display = self.query?'block':'none'; |
| 129 | + if(self.query){ |
| 130 | + self.searchResult(); |
| 131 | + }else{ |
| 132 | + self.elm_result.style.display = 'none'; |
| 133 | + } |
| 134 | + if(!self.elm_search_result){ |
| 135 | + self.elm_result.style.display = self.query?'block':'none'; |
| 136 | + }else{ |
| 137 | + self.elm_btn.click(); |
| 138 | + } |
130 | 139 | })
|
131 | 140 | this.bindEvent(this.elm_btn,'click',function(e){
|
132 |
| - console.log("---->") |
133 |
| - if(self.elm_search_result){ |
134 |
| - self.searchResult(true); |
135 |
| - } |
| 141 | + self.elm_result.style.display = 'none'; |
| 142 | + if(self.elm_search_result) self.searchResult(true); |
136 | 143 | else{
|
137 | 144 | window.location.href = self.root_path + '/list.html#!kw='+self.query;
|
138 | 145 | }
|
139 | 146 | })
|
140 | 147 | this.bindEvent(this.elm_query,'focus',function(e){
|
141 | 148 | self.searchResult();
|
142 |
| - self.elm_result.style.display = 'block'; |
| 149 | + if(self.query)self.elm_result.style.display = 'block'; |
143 | 150 | })
|
144 | 151 | this.bindEvent(this.elm_query,'blur',function(e){
|
145 | 152 | timer = setTimeout(function(){
|
146 | 153 | self.elm_result.style.display = 'none';
|
147 |
| - },600) |
| 154 | + },300) |
148 | 155 | })
|
| 156 | + // 输入Enter键 |
| 157 | + this.bindEvent(document,'keyup',function(e){ |
| 158 | + if(e.key =='Enter'){ |
| 159 | + self.elm_btn.click(); |
| 160 | + } |
| 161 | + }) |
| 162 | + |
149 | 163 | if(kw) self.searchResult();
|
150 | 164 | }
|
151 | 165 | }
|
|
0 commit comments