表单自动补全,从后台传值与id进来,并且将id值提交给后台

 1 //从后台获取数据,转换成数组格式
 2 
 3 var autoComplete = new AutoComplete('keyword', 'auto', [<?php foreach($jqname as $key => $dd){$str=$str."'".$dd['title']."',";}$str=substr($str,0,$str.length-1);echo $str; ?>]);
 4 
 5  
 6 
 7 //从后台获取数据,并将其转换成为json格式,设置隐藏域
 8 
 9 <input type="hidden" value='<?php echo json_encode($jqname) ?>' id="jq_json" />
10 
11  
12 
13 //设置隐藏域,存放id值
14 
15 <input type="hidden" id="jqid" name="jqid" value="" />
16 
17  
18 
19 //在鼠标事件和键盘事件中添加,动态设置id值
20 
21 //模拟鼠标移动至DIV时,DIV高亮 
22 
23         autoOnmouseover : function(_this, _div_index) { 
24             return function() { 
25                 _this.index = _div_index; 
26                 var length = _this.autoObj.children.length; 
27                 for ( var j = 0; j < length; j++) { 
28                     if (j != _this.index) { 
29                         _this.autoObj.childNodes[j].className = 'auto_onmouseout'; 
30                     } else { 
31                         _this.autoObj.childNodes[j].className = 'auto_onmouseover'; 
32                         _this.obj.value = _this.autoObj.childNodes[j].seq;
33                         var jq_json=document.getElementById("jq_json").value;
34                         var data = eval(jq_json);//格式化成数组
35                         for(var t = 0; t<data.length; t++){
36                             if(data[t]['title']==_this.obj.value){
37                                 var td=document.getElementById("jqid");
38                                 td.value=data[t]['aid'];
39                                 break;
40                             }
41                         }
42                     } 
43                 } 
44             } 
45         }, 
46 
47         //更改classname 
48         changeClassname : function(length) {
49             for ( var i = 0; i < length; i++) { 
50                 if (i != this.index) { 
51                     this.autoObj.childNodes[i].className = 'auto_onmouseout'; 
52                 } else { 
53                     this.autoObj.childNodes[i].className = 'auto_onmouseover'; 
54                     this.obj.value = this.autoObj.childNodes[i].seq;
55 
56                     var jq_json=document.getElementById("jq_json").value;
57                     var data = eval(jq_json);//格式化成数组
58 
59                     for(var j = 0; j<data.length; j++){
60                         if(data[j]['title']==this.obj.value){
61                             var td=document.getElementById("jqid");
62                             td.value=data[j]['aid'];
63                             break;
64                         }
65                     }
66 
67                 } 
68 
69             } 
70 
71         },  

参考网址:http://blog.csdn.net/malinjie66/article/details/9281443
posted @ 2016-01-21 15:56  北斗星空的笨小孩  阅读(850)  评论(0)    收藏  举报