DWR实现Ajax自动提示
Code
1/**//**
2 * AJAX 自动完成代码,公司编号下拉框
3 */
4var array;
5var xhttp;
6var zz=-1; // 此为指针
7// 函数生成下拉列表
8function buildList(){
9 zz=-1;
10 $('search_suggest').innerHTML='';
11 for(var i=0;i<array.length-1;i++){
12 if(array!=""){
13 document.getElementById("search_suggest").innerHTML+="<div id='item" + i +
14 "' class='item_normal' onmouseover='beMouseOver(" + i +
15 ")' onmouseout='beMouseOut(" + i + ")' onclick='beClick(" + i +
16 ")'>" + array[i][0]+"|"+array[i][1] + "</div>";
17 }
18 }// for循环
19}// 函数
20
21// beKeyUp事件,调用与服务器通信方法
22function beKeyUp(){
23 if(event.keyCode!=13&event.keyCode!=9&event.keyCode!=38&event.keyCode!=40){
24 findNames();
25 }
26}
27// 与服务器通迅
28function findNames(){
29 if($('txtCompany').value.length > 0){
30 // dwr方法
31 CompanyUtil.findByKeywordDWR($('txtCompany').value,callback);
32 }else{
33 //********清空层显示信息
34 $('divCompany').innerHTML="";
35
36 $('txtCompany').className="key_normal";
37 document.getElementById("search_suggest").className="suggest_hidden";
38 $('txtCompany').focus();
39 }
40}
41
42function callback(data){
43 if(data!=null && data.length>1){
44 array=data;
45 buildList();
46 $('txtCompany').className="key_abnormal";
47 document.getElementById("search_suggest").className="search_suggest";
48 }else{
49 //********清空层显示信息
50 $('divCompany').innerHTML="";
51
52 $('txtCompany').className="key_normal";
53 document.getElementById("search_suggest").className="suggest_hidden";
54 }
55}
56
57
58// 函数鼠标经过效果
59function beMouseOverEFF(i){
60 if ((i>=0)&(i<array.length-1)){
61 document.getElementById("item" + i).className="item_high";
62 }
63}
64
65// 函数鼠标移开效果
66function beMouseOutEFF(i){
67 if ((i>=0)&(i<array.length)){
68 document.getElementById("item" + i).className="item_normal";
69 }
70}
71
72// 函数鼠标经过
73function beMouseOver(i){
74 $('txtCompany').focus();
75 beMouseOutEFF(zz);
76 zz=i;
77 beMouseOverEFF(zz);
78}
79
80// 函数鼠标移开
81function beMouseOut(i){
82}
83// 函数单击
84function beClick(i){
85 $('txtCompany').value=array[i][0];
86 //设置公司信息到文本框
87 //$('deliver.companyNo').value=array[i][0];
88 $('divCompany').innerHTML="<span class='gray'>名称:"+array[i][1]+" 公司总机:"+array[i][2]+"</span>";
89
90 $('txtCompany').className="key_normal";
91 document.getElementById("search_suggest").className="suggest_hidden";
92 $('txtCompany').focus();
93}
94
95// 方向键接收函数
96function beKeyDown(){
97if(array!=null){
98// 往下按
99 if (event.keyCode==40){
100 if(zz<array.length-2){
101 beMouseOutEFF(zz++);
102 }
103 if(zz<=array.length-1){
104 beMouseOverEFF(zz);
105 }
106 }
107}
108
109 // 往上按
110 if (event.keyCode==38){
111 if (zz>0){
112 beMouseOutEFF(zz--);
113 }
114 if (zz>=0){
115 beMouseOverEFF(zz);
116 }
117 }
118
119 // 按回车或者TAB
120 if (event.keyCode==13||event.keyCode==9){
121 if (zz!=-1){
122 beClick(zz);
123 }
124 else
125 {
126 $('txtCompany').focus();
127 }
128 }
129}
130function beOnBlur(){
131
132}
133
134
135
136
137
138
139//**************************************************************************
140/**//**
141 * AJAX 自动完成代码,会员`大客户`同行编号下拉框
142 */
143var array2;
144var xhttp2;
145var zz2=-1; // 此为指针
146// 函数生成下拉列表
147function buildList2(){
148 zz2=-1;
149 $('search_suggest2').innerHTML='';
150 for(i=0;i<array2.length-1;i++){
151 if(array2!=""){
152 document.getElementById("search_suggest2").innerHTML+="<div id='jtem" + i +
153 "' class='item_normal' onmouseover='beMouseOver2(" + i +
154 ")' onmouseout='beMouseOut2(" + i + ")' onclick='beClick2(" + i +
155 ")'>" + array2[i][0]+"|"+array2[i][1] + "</div>";
156 }
157 }// for循环
158
159}// 函数
160
161// beKeyUp2事件,调用与服务器通信方法
162function beKeyUp2(){
163 if(event.keyCode!=13&event.keyCode!=9&event.keyCode!=38&event.keyCode!=40){
164 findNames2();
165 }
166}
167// 与服务器通迅
168function findNames2(){
169
170 // dwr方法
171
172 if($('txtMember').value.length > 0){
173 // dwr方法
174 MemberUtil.findByKeywordDWR($('txtCompany').value,$('txtMember').value,callback2);
175 }else{
176 //********清空层显示信息
177 $('divMember').innerHTML="";
178
179 $('txtMember').className="key_normal";
180 document.getElementById("search_suggest2").className="suggest_hidden";
181 $('txtMember').focus();
182 }
183}
184
185function callback2(data2){
186 if(data2!=null && data2.length>1){
187 array2=data2;
188 buildList2();
189 $('txtMember').className="key_abnormal";
190 document.getElementById("search_suggest2").className="search_suggest";
191 }else{
192 //********清空层显示信息
193 $('divMember').innerHTML="";
194 $('deliver.destineName').value="";
195 $('deliver.recivName').value="";
196
197 DWRUtil.removeAllOptions($('destineTelSelect'));
198 DWRUtil.removeAllOptions($('recivTelSelect'));
199 DWRUtil.removeAllOptions($('deliver.address'));
200
201 $('txtMember').className="key_normal";
202 document.getElementById("search_suggest2").className="suggest_hidden";
203 }
204}
205
206
207// 函数鼠标经过效果
208function beMouseOver2EFF2(i){
209 if ((i>=0)&(i<array2.length-1)){
210 document.getElementById("jtem" + i).className="item_high";
211 }
212}
213
214// 函数鼠标移开效果
215function beMouseOut2EFF2(i){
216 if ((i>=0)&(i<array2.length)){
217 document.getElementById("jtem" + i).className="item_normal";
218 }
219}
220
221// 函数鼠标经过
222function beMouseOver2(i){
223 $('txtMember').focus();
224 beMouseOut2EFF2(zz2);
225 zz2=i;
226 beMouseOver2EFF2(zz2);
227}
228
229// 函数鼠标移开
230function beMouseOut2(i){
231}
232// 函数单击
233function beClick2(i){
234 $('txtMember').value=array2[i][0];
235 $('txtMember').className="key_normal";
236
237 /**//**
238 * 设置会员信息
239 * */
240 //判断会员性别(只有会员存在)
241 var gender="";
242 if(array2[i][2]!=null && array2[i][2]!="")
243 {
244 if(array2[i][2]=="1"){
245 gender="先生";
246 }else{
247 gender="女士";
248 }
249 }
250 //alert(gender);
251 //设置div会员信息
252 var html = "<span class='gray'>姓名:"+array2[i][1]+gender+"("+array2[i][6]+") 电话:"
253 +array2[i][3]+" 业务员:"+array2[i][7]+"</span>";
254 //alert(html);
255 $('divMember').innerHTML=html;
256
257 //设置textbox会员信息
258 /**//*
259 $('deliver.destineName').value=array2[i][1];
260 $('deliver.destineTel').value=array2[i][3];
261 $('deliver.destineOtherTel').value=array2[i][4];
262 //$('address').value=array2[i][5];
263
264 $('deliver.recivName').value=array2[i][1];
265 $('deliver.recivTel').value=array2[i][3];
266 $('deliver.recivOtherTel').value=array2[i][4];
267 $('deliver.address').value=array2[i][5];
268 */
269
270 /**//**
271 * 设置textbox会员信息
272 */
273 $('deliver.destineName').value=array2[i][1];//设置预订人姓名
274 $('deliver.recivName').value=array2[i][1];//收件人姓名
275
276 /**//**
277 * 设置下拉框电话号码
278 */
279 //截取电话号码,转成数组
280 var telStr = array2[i][4];
281 var arrayStr = telStr.split(",");
282
283 var selArray=$('destineTelSelect');
284 for(j=0;j<arrayStr.length;j++){
285 selArray.options[selArray.length]=new Option(arrayStr[j]);
286 }
287 //第二个下拉框
288 var selArray2=$('recivTelSelect');
289 for(j=0;j<arrayStr.length;j++){
290 selArray2.options[selArray2.length]=new Option(arrayStr[j]);
291 }
292
293
294 /**//**
295 *设置下拉框送件地址
296 * deliver.address
297 */
298 //alert(i);
299 //alert(array2[i]);
300
301 var addressStr = array2[i][8];
302 //alert(addressStr)
303
304 var arrayStr2 = addressStr.split(",");
305
306 //var selArray=document.getElementsByTagName("select");
307 var selAddress=$('deliver.address');
308
309 for(j=0;j<arrayStr2.length;j++){
310 selAddress.options[selAddress.length]=new Option(arrayStr2[j]);
311 }
312
313 document.getElementById("search_suggest2").className="suggest_hidden";
314 $('txtMember').focus();
315}
316
317// 方向键接收函数
318function beKeyDown2(){
319if(array2!=null){
320// 往下按
321 if (event.keyCode==40){
322 if(zz2<array2.length-2){
323 beMouseOut2EFF2(zz2++);
324 }
325 if(zz2<=array2.length-1){
326 beMouseOver2EFF2(zz2);
327 }
328 }
329}
330
331 // 往上按
332 if (event.keyCode==38){
333 if (zz2>0){
334 beMouseOut2EFF2(zz2--);
335 }
336 if (zz2>=0){
337 beMouseOver2EFF2(zz2);
338 }
339 }
340
341 // 按回车或者TAB
342 if (event.keyCode==13||event.keyCode==9){
343 if (zz2!=-1){
344 beClick2(zz2);
345 }
346 else
347 {
348 $('txtMember').focus();
349 }
350 }
351}
352function beOnBlur2(){
353
354}
355
356
357/**//**************************************************************/
358/**//**
359 * 设置送达结束时间,晚于送达开始时间半小时
360 */
361function setEndTime(sel){
362 var index = parseInt(sel.value);
363 var endtime = $('selEndTime');
364 /**//*删除后,无法复原
365 for(j=0;j<endtime.length-1;j++){
366 if(endtime.options[j].value<index){
367 endtime.remove(j);
368 j--;//没删除一个j层的索引就会+1;所以要j--
369 }
370 }*/
371
372 DWRUtil.removeAllOptions(endtime);
373 for(j=0;j<sel.length;j++){
374 if(sel.options[j].value>=index){
375 endtime.options[endtime.length]=new Option(sel[j].text,sel[j].value);
376 }
377 }
378
379
380 endtime.value=index+1;//默认结束送达时间推迟半小时
381}
382
383
1/**//**
2 * AJAX 自动完成代码,公司编号下拉框
3 */
4var array;
5var xhttp;
6var zz=-1; // 此为指针
7// 函数生成下拉列表
8function buildList(){
9 zz=-1;
10 $('search_suggest').innerHTML='';
11 for(var i=0;i<array.length-1;i++){
12 if(array!=""){
13 document.getElementById("search_suggest").innerHTML+="<div id='item" + i +
14 "' class='item_normal' onmouseover='beMouseOver(" + i +
15 ")' onmouseout='beMouseOut(" + i + ")' onclick='beClick(" + i +
16 ")'>" + array[i][0]+"|"+array[i][1] + "</div>";
17 }
18 }// for循环
19}// 函数
20
21// beKeyUp事件,调用与服务器通信方法
22function beKeyUp(){
23 if(event.keyCode!=13&event.keyCode!=9&event.keyCode!=38&event.keyCode!=40){
24 findNames();
25 }
26}
27// 与服务器通迅
28function findNames(){
29 if($('txtCompany').value.length > 0){
30 // dwr方法
31 CompanyUtil.findByKeywordDWR($('txtCompany').value,callback);
32 }else{
33 //********清空层显示信息
34 $('divCompany').innerHTML="";
35
36 $('txtCompany').className="key_normal";
37 document.getElementById("search_suggest").className="suggest_hidden";
38 $('txtCompany').focus();
39 }
40}
41
42function callback(data){
43 if(data!=null && data.length>1){
44 array=data;
45 buildList();
46 $('txtCompany').className="key_abnormal";
47 document.getElementById("search_suggest").className="search_suggest";
48 }else{
49 //********清空层显示信息
50 $('divCompany').innerHTML="";
51
52 $('txtCompany').className="key_normal";
53 document.getElementById("search_suggest").className="suggest_hidden";
54 }
55}
56
57
58// 函数鼠标经过效果
59function beMouseOverEFF(i){
60 if ((i>=0)&(i<array.length-1)){
61 document.getElementById("item" + i).className="item_high";
62 }
63}
64
65// 函数鼠标移开效果
66function beMouseOutEFF(i){
67 if ((i>=0)&(i<array.length)){
68 document.getElementById("item" + i).className="item_normal";
69 }
70}
71
72// 函数鼠标经过
73function beMouseOver(i){
74 $('txtCompany').focus();
75 beMouseOutEFF(zz);
76 zz=i;
77 beMouseOverEFF(zz);
78}
79
80// 函数鼠标移开
81function beMouseOut(i){
82}
83// 函数单击
84function beClick(i){
85 $('txtCompany').value=array[i][0];
86 //设置公司信息到文本框
87 //$('deliver.companyNo').value=array[i][0];
88 $('divCompany').innerHTML="<span class='gray'>名称:"+array[i][1]+" 公司总机:"+array[i][2]+"</span>";
89
90 $('txtCompany').className="key_normal";
91 document.getElementById("search_suggest").className="suggest_hidden";
92 $('txtCompany').focus();
93}
94
95// 方向键接收函数
96function beKeyDown(){
97if(array!=null){
98// 往下按
99 if (event.keyCode==40){
100 if(zz<array.length-2){
101 beMouseOutEFF(zz++);
102 }
103 if(zz<=array.length-1){
104 beMouseOverEFF(zz);
105 }
106 }
107}
108
109 // 往上按
110 if (event.keyCode==38){
111 if (zz>0){
112 beMouseOutEFF(zz--);
113 }
114 if (zz>=0){
115 beMouseOverEFF(zz);
116 }
117 }
118
119 // 按回车或者TAB
120 if (event.keyCode==13||event.keyCode==9){
121 if (zz!=-1){
122 beClick(zz);
123 }
124 else
125 {
126 $('txtCompany').focus();
127 }
128 }
129}
130function beOnBlur(){
131
132}
133
134
135
136
137
138
139//**************************************************************************
140/**//**
141 * AJAX 自动完成代码,会员`大客户`同行编号下拉框
142 */
143var array2;
144var xhttp2;
145var zz2=-1; // 此为指针
146// 函数生成下拉列表
147function buildList2(){
148 zz2=-1;
149 $('search_suggest2').innerHTML='';
150 for(i=0;i<array2.length-1;i++){
151 if(array2!=""){
152 document.getElementById("search_suggest2").innerHTML+="<div id='jtem" + i +
153 "' class='item_normal' onmouseover='beMouseOver2(" + i +
154 ")' onmouseout='beMouseOut2(" + i + ")' onclick='beClick2(" + i +
155 ")'>" + array2[i][0]+"|"+array2[i][1] + "</div>";
156 }
157 }// for循环
158
159}// 函数
160
161// beKeyUp2事件,调用与服务器通信方法
162function beKeyUp2(){
163 if(event.keyCode!=13&event.keyCode!=9&event.keyCode!=38&event.keyCode!=40){
164 findNames2();
165 }
166}
167// 与服务器通迅
168function findNames2(){
169
170 // dwr方法
171
172 if($('txtMember').value.length > 0){
173 // dwr方法
174 MemberUtil.findByKeywordDWR($('txtCompany').value,$('txtMember').value,callback2);
175 }else{
176 //********清空层显示信息
177 $('divMember').innerHTML="";
178
179 $('txtMember').className="key_normal";
180 document.getElementById("search_suggest2").className="suggest_hidden";
181 $('txtMember').focus();
182 }
183}
184
185function callback2(data2){
186 if(data2!=null && data2.length>1){
187 array2=data2;
188 buildList2();
189 $('txtMember').className="key_abnormal";
190 document.getElementById("search_suggest2").className="search_suggest";
191 }else{
192 //********清空层显示信息
193 $('divMember').innerHTML="";
194 $('deliver.destineName').value="";
195 $('deliver.recivName').value="";
196
197 DWRUtil.removeAllOptions($('destineTelSelect'));
198 DWRUtil.removeAllOptions($('recivTelSelect'));
199 DWRUtil.removeAllOptions($('deliver.address'));
200
201 $('txtMember').className="key_normal";
202 document.getElementById("search_suggest2").className="suggest_hidden";
203 }
204}
205
206
207// 函数鼠标经过效果
208function beMouseOver2EFF2(i){
209 if ((i>=0)&(i<array2.length-1)){
210 document.getElementById("jtem" + i).className="item_high";
211 }
212}
213
214// 函数鼠标移开效果
215function beMouseOut2EFF2(i){
216 if ((i>=0)&(i<array2.length)){
217 document.getElementById("jtem" + i).className="item_normal";
218 }
219}
220
221// 函数鼠标经过
222function beMouseOver2(i){
223 $('txtMember').focus();
224 beMouseOut2EFF2(zz2);
225 zz2=i;
226 beMouseOver2EFF2(zz2);
227}
228
229// 函数鼠标移开
230function beMouseOut2(i){
231}
232// 函数单击
233function beClick2(i){
234 $('txtMember').value=array2[i][0];
235 $('txtMember').className="key_normal";
236
237 /**//**
238 * 设置会员信息
239 * */
240 //判断会员性别(只有会员存在)
241 var gender="";
242 if(array2[i][2]!=null && array2[i][2]!="")
243 {
244 if(array2[i][2]=="1"){
245 gender="先生";
246 }else{
247 gender="女士";
248 }
249 }
250 //alert(gender);
251 //设置div会员信息
252 var html = "<span class='gray'>姓名:"+array2[i][1]+gender+"("+array2[i][6]+") 电话:"
253 +array2[i][3]+" 业务员:"+array2[i][7]+"</span>";
254 //alert(html);
255 $('divMember').innerHTML=html;
256
257 //设置textbox会员信息
258 /**//*
259 $('deliver.destineName').value=array2[i][1];
260 $('deliver.destineTel').value=array2[i][3];
261 $('deliver.destineOtherTel').value=array2[i][4];
262 //$('address').value=array2[i][5];
263
264 $('deliver.recivName').value=array2[i][1];
265 $('deliver.recivTel').value=array2[i][3];
266 $('deliver.recivOtherTel').value=array2[i][4];
267 $('deliver.address').value=array2[i][5];
268 */
269
270 /**//**
271 * 设置textbox会员信息
272 */
273 $('deliver.destineName').value=array2[i][1];//设置预订人姓名
274 $('deliver.recivName').value=array2[i][1];//收件人姓名
275
276 /**//**
277 * 设置下拉框电话号码
278 */
279 //截取电话号码,转成数组
280 var telStr = array2[i][4];
281 var arrayStr = telStr.split(",");
282
283 var selArray=$('destineTelSelect');
284 for(j=0;j<arrayStr.length;j++){
285 selArray.options[selArray.length]=new Option(arrayStr[j]);
286 }
287 //第二个下拉框
288 var selArray2=$('recivTelSelect');
289 for(j=0;j<arrayStr.length;j++){
290 selArray2.options[selArray2.length]=new Option(arrayStr[j]);
291 }
292
293
294 /**//**
295 *设置下拉框送件地址
296 * deliver.address
297 */
298 //alert(i);
299 //alert(array2[i]);
300
301 var addressStr = array2[i][8];
302 //alert(addressStr)
303
304 var arrayStr2 = addressStr.split(",");
305
306 //var selArray=document.getElementsByTagName("select");
307 var selAddress=$('deliver.address');
308
309 for(j=0;j<arrayStr2.length;j++){
310 selAddress.options[selAddress.length]=new Option(arrayStr2[j]);
311 }
312
313 document.getElementById("search_suggest2").className="suggest_hidden";
314 $('txtMember').focus();
315}
316
317// 方向键接收函数
318function beKeyDown2(){
319if(array2!=null){
320// 往下按
321 if (event.keyCode==40){
322 if(zz2<array2.length-2){
323 beMouseOut2EFF2(zz2++);
324 }
325 if(zz2<=array2.length-1){
326 beMouseOver2EFF2(zz2);
327 }
328 }
329}
330
331 // 往上按
332 if (event.keyCode==38){
333 if (zz2>0){
334 beMouseOut2EFF2(zz2--);
335 }
336 if (zz2>=0){
337 beMouseOver2EFF2(zz2);
338 }
339 }
340
341 // 按回车或者TAB
342 if (event.keyCode==13||event.keyCode==9){
343 if (zz2!=-1){
344 beClick2(zz2);
345 }
346 else
347 {
348 $('txtMember').focus();
349 }
350 }
351}
352function beOnBlur2(){
353
354}
355
356
357/**//**************************************************************/
358/**//**
359 * 设置送达结束时间,晚于送达开始时间半小时
360 */
361function setEndTime(sel){
362 var index = parseInt(sel.value);
363 var endtime = $('selEndTime');
364 /**//*删除后,无法复原
365 for(j=0;j<endtime.length-1;j++){
366 if(endtime.options[j].value<index){
367 endtime.remove(j);
368 j--;//没删除一个j层的索引就会+1;所以要j--
369 }
370 }*/
371
372 DWRUtil.removeAllOptions(endtime);
373 for(j=0;j<sel.length;j++){
374 if(sel.options[j].value>=index){
375 endtime.options[endtime.length]=new Option(sel[j].text,sel[j].value);
376 }
377 }
378
379
380 endtime.value=index+1;//默认结束送达时间推迟半小时
381}
382
383