⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 suggest.js

📁 公交网源代码,无上下行 下载后数据库在DATE目录下, 可修改CONFIG文件
💻 JS
字号:
function jsAuto(instanceName,objID){
	this._msg = [];
	this._x = null;
	this._o = document.getElementById(objID);//获取suggest对象
	if (!this._o) return;
	this._f = null;
	this._i = instanceName;
	this._r = null;
	this._c = 0;
	this._s = false;
	this._v = null;
	this._o.style.visibility = "hidden";
	this._o.style.position = "absolute";
	this._o.style.zIndex = "9999";
	return this;
};

//键盘事件
jsAuto.prototype.directionKey=function(){ with (this)
	{
	var e = _e.keyCode ? _e.keyCode : _e.which;
	var l = _o.childNodes.length;
	(_c>l-1 || _c<0) ? _s=false : "";	
	if( e==40 && _s ){
		_o.childNodes[_c].className="mouseout";
		(_c >= l-1) ? _c=0 : _c ++;
		_o.childNodes[_c].className="mouseover";
	 }
	 if( e==38 && _s ){
		_o.childNodes[_c].className="mouseout";
		_c--<=0 ? _c = _o.childNodes.length-1 : "";
		_o.childNodes[_c].className="mouseover";
	 }
	 if( e==13 ){//回车键
		if(_o.childNodes[_c] && _o.style.visibility=="visible"){
			_r.value = _x[_c];
			_o.style.visibility = "hidden";
		}
	 }
	 if( !_s ){
	  _c = 0;
	  _o.childNodes[_c].className="mouseover";
	  _s = true;
	 }
	}
};


// mouseEvent.
jsAuto.prototype.domouseover=function(obj) { with (this){
	_o.childNodes[_c].className = "mouseout";
	_c = 0;
	obj.tagName=="DIV" ? obj.className="mouseover" : obj.parentElement.className="mouseover";
}};

jsAuto.prototype.domouseout=function(obj){
	obj.tagName=="DIV" ? obj.className="mouseout" : obj.parentElement.className="mouseout";
};

jsAuto.prototype.doclick=function(msg) { with (this){
	if(_r){
		_r.value = msg;
		_o.style.visibility = "hidden";
	}
	else{
		alert("javascript autocomplete ERROR :\n\n can not get return object.");
	return;
	}
}};

// object method;
jsAuto.prototype.item=function(msg){//装入数据
	if( msg.indexOf("|")>0 ){
		var arrMsg=msg.split("|");
		for(var i=0; i<arrMsg.length; i++){
			arrMsg[i] ? this._msg.push(arrMsg[i]) : "";
		}
	}
	else{
		this._msg.push(msg);
	}
	this._msg.sort();
};

jsAuto.prototype.append=function(msg) { with (this){
	_i ? "" : _i = eval(_i);
	_x.push(msg);
	var div = document.createElement("DIV");
	//bind event to object.
	div.onmouseover = function(){_i.domouseover(this)};
	div.onmouseout = function(){_i.domouseout(this)};
	div.onclick = function(){_i.doclick(msg)};
	var re  = new RegExp("(" + _v + ")","i");
	div.style.lineHeight="140%";
	div.className = "mouseout";
	if(_v){
		div.innerHTML = msg.replace(re , "<strong class='doaa'>$1</strong>");
	}
	div.style.fontFamily = "verdana";
	_o.appendChild(div);
}};

jsAuto.prototype.display=function() { with(this){
	if(_f&&(_v!="")){
		if(document.all){//当为IE时
		_o.style.left = _r.offsetLeft;
		_o.style.top = _r.offsetTop+_r.clientHeight;
		_o.style.width = _r.offsetWidth-2;//控件宽度,-2是去掉边框
		}
		else{//当为FF时,FF一定要加单位‘px’
		_o.style.left = eval('"'+_r.offsetLeft+'px"');
		_o.style.top = eval('"'+(_r.offsetTop+_r.clientHeight)+'px"');
		_o.style.width = eval('"'+(_r.offsetWidth-2)+'px"');//控件宽度,-2是去掉边框		
		}
		_o.style.visibility = "visible";
		
	}
	else{
		_o.style.visibility="hidden";
	}
}};

jsAuto.prototype.handleEvent=function(fValue,fID,event) { with (this){
	//if(!document.all){return;}//非ie浏览器,阻止执行本函数
	if (fValue!=""){//当输入的关键字不为空
		var re;
		_e = event;
		var e = _e.keyCode ? _e.keyCode : _e.which;
		_x = [];
		_f = false;
		_r = document.getElementById( fID );//得到输入框对象
		_v = fValue;
		_i = eval(_i);
		re = new RegExp(fValue, "i");//匹配关键字
		_o.innerHTML="";
		for(var i=0; i<_msg.length; i++){
			if(re.test(_msg[i])){
				_i.append(_msg[i]);
				_f = true;
			}
		}	
		_i ? _i.display() : alert("can not get instance");	
		if(_f){
			if((e==38 || e==40 || e==13)){
				_i.directionKey();
			}
			else{
				_c=0;
				_o.childNodes[_c].className = "mouseover";
				_s=true;
			}
		}
 	}
	else{
		_o.style.visibility = "hidden";
	}//if结束
}};

jsAuto.prototype.hidden=function() { with (this){//隐藏建议列表
	//if(!document.all){return;}//非ie浏览器,阻止执行本函数
 	_o.style.visibility = "hidden";
}};


//window.onerror=new Function("return true;");//消除错误
/*创建新项目
var jsAutoInstance = new jsAuto("jsAutoInstance","suggest");//suggest为建议下拉菜单所在的层
stops=_lineClass.split("|");//从“_lineData.js”引入变量_lineClass的站点分类数组值
for (i=0;i<stops.length; i++){ 
	jsAutoInstance.item(eval("_line"+stops[i]));
}
*/

//////选择字符母分类建议/////////////////
function lineName(){//自动生成分类字母
	linename=document.getElementById("linenamess");
	linename.options[0] = new Option("请选择线路","");
	a=_siteName.split("|");//从“_lineData.js”引入变量_lineClass的站点分类数组值
	b=_siteMark.split("|");//从“_lineData.js”引入变量_lineClass的站点分类数组值
	for (i=0;i<a.length; i++){ 
		linename.options[i+1] = new Option(a[i],b[i]);
	}
}

function abc(letter){//自动生成分类字母
	letter=document.getElementById(letter);
	letter.options[0] = new Option("分类","");
	lines=_lineClass.split("|");//从“_lineData.js”引入变量_lineClass的站点分类数组值
	for (i=0;i<lines.length; i++){ 
		letter.options[i+1] = new Option(lines[i],lines[i]);
	}
}
function changelocation(id,line) 
{
	line=document.getElementById(line);
	if (id==""){
		line.options.length = 1;
		line.options[0] = new Option("<-|请先选择分类","");		
	}
	else{
		line.options[0] = new Option("选择站点["+id+"]","");
		stops=eval("_line"+id);
		stops=stops.split("|");
		for (i=0;i<stops.length; i++){ 
			line.options[i+1] = new Option(stops[i],stops[i]);
		}
	}          
}
////////////检验提交表单的函数/////////////////////////
function so1(auto){
	var A=document.getElementById('A');
	var B=document.getElementById('B');
	if(A.value ==""){
		alert("请输入起点名称!");
		A.focus();
		return false;
	}
	if(B.value ==""){
		alert("请输入终点名称!");
		B.focus();
		return false;
	}
	if(A.value == B.value){
		alert("起点名称和终点名称不允许相同!");
		B.focus();
		return false;
	}
	if (checksite(A.value)==false){
		A.focus();
		return false;
	}
	if (checksite(B.value)==false){
		B.focus();
		return false;
	}
	if(auto=="auto"){
		window.location.href="so.php?A="+A.value+"&B="+B.value;
	}
	else{
		window.location.href="so.php?so=1&A="+A.value+"&B="+B.value;
	
	}
}
function so2(){
	var linenamess=document.getElementById('linenamess');
	if(linenamess.value ==""){
		alert("请选择站点!");
		linenamess.focus();
		return false;
	}
	window.location.href="lines\/"+linenamess.value+".html";
}

function so3(){
	var C=document.getElementById('C');
	if(C.value ==""){
		alert("请输入查询站点名称!");
		C.focus();
		return false;
	}
	if (checksite(C.value)==false){
		C.focus();
		return false;
	}
	window.location.href="ss.php?C="+C.value;
}

function checksite(site){//检查表单是否存在
	var f=false;
	var msg=jsAutoInstance._msg;
	for(var i=0; i<msg.length; i++){
		if(site==msg[i]){
			f=true;
		}
	}
	if (f==false){
		alert("站点《"+site+"》不存在!\n请你重新输入或选择站点!!");
		return false;
	}
	else{
		return true;	
	}
}

function addFavorite(){//加入收藏夹
	window.external.addFavorite(window.location.href,document.title);	
}

//////////////自动函数//////////////////////////////////
function doo(){//页页自动加载本函数
	lineName();
	abc("letterA");	
	abc("letterB");	
}
window.onload=doo;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -