标签:
从后台获取数据,转换成数组格式
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;
}
}
}
}
},
标签:
原文地址:http://www.cnblogs.com/srxhmxx/p/5148568.html