码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-01-21 18:45:54      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:

从后台获取数据,转换成数组格式

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; ?>]);

 

从后台获取数据,并将其转换成为json格式,设置隐藏域

<input type="hidden" value=‘<?php echo json_encode($jqname) ?>‘ id="jq_json" />

 

设置隐藏域,存放id

<input type="hidden" id="jqid" name="jqid" value="" />

 

在鼠标事件和键盘事件中添加,动态设置id

//模拟鼠标移动至DIV时,DIV高亮 

        autoOnmouseover : function(_this, _div_index) { 

            return function() { 

                _this.index = _div_index; 

                var length = _this.autoObj.children.length; 

                for ( var j = 0; j < length; j++) { 

                    if (j != _this.index) { 

                        _this.autoObj.childNodes[j].className = ‘auto_onmouseout‘; 

                    } else { 

                        _this.autoObj.childNodes[j].className = ‘auto_onmouseover‘; 

 

                        _this.obj.value = _this.autoObj.childNodes[j].seq;

                        var jq_json=document.getElementById("jq_json").value;

                        var data = eval(jq_json);//格式化成数组

                        for(var t = 0; t<data.length; t++){

                            if(data[t][‘title‘]==_this.obj.value){

                                var td=document.getElementById("jqid");

                                td.value=data[t][‘aid‘];

                                break;

                            }

                        }

 

 

                    } 

                } 

            } 

        }, 

        //更改classname 

        changeClassname : function(length) {

            for ( var i = 0; i < length; i++) { 

                if (i != this.index) { 

 

                    this.autoObj.childNodes[i].className = ‘auto_onmouseout‘; 

                } else { 

                    this.autoObj.childNodes[i].className = ‘auto_onmouseover‘; 

                    this.obj.value = this.autoObj.childNodes[i].seq;

 

                    var jq_json=document.getElementById("jq_json").value;

                    var data = eval(jq_json);//格式化成数组

                    for(var j = 0; j<data.length; j++){

                        if(data[j][‘title‘]==this.obj.value){

                            var td=document.getElementById("jqid");

                            td.value=data[j][‘aid‘];

                            break;

                        }

                    }

                   

                } 

            } 

        },  

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

标签:

原文地址:http://www.cnblogs.com/srxhmxx/p/5148568.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!