Google智能提示

先来看看共有三个文件,test.htm文件是测试文件,css.css样式列表,google.js就是js处理文件了.下面我把代码一一写出来,给大家分享.
test.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
    <link href="tooltip.css" rel="stylesheet" type="text/css" />
    <script src="tooltip.js" language="javascript"></script>
    <script language="javascript">
        function test()
        {
            var obj = document.getElementById("msg");
            obj.innerText = "测试成功";
        }
        function ShowWin()
        {
            var pop = window.createPopup();
            var doc = pop.document;
            var body = doc.body;
            doc.createStyleSheet("tooltip.css");
            body.innerHTML = document.getElementById("list").outerHTML ;
            pop.show(100, 100, 200, 200, document.body);
        }
    </script>
</head>
<body>
<span id="msg"></span>
<input type="text" onkeyup="GTTa.OnKeyUp(this);" style="width:200px;" />
<input type="button" value="测试" onclick="ShowWin()" />
    <script language="javascript">
        var GTTa = new AIToolTip();
    </script>
    <div class="tooltip" style="display:none;">
    <a href="#">1</a>
    </div>
</body>
</html>
test文件的代码简单直接复制保存成一个html文件就行了.
下面来看css文件的内容:
.body
{
    margin: 0px;
}
.tooltip
{
    border-right: black 1px solid;
    border-top: black 1px solid;
    font-size: 9pt;
    border-left: black 1px solid;
    border-bottom: black 1px solid;
    font-family: 宋体;
    background-color: white;
    position: absolute;
    z-index: 10;
    width:100%;
}
.tooltip a
{
    display: block;
    padding-top: 5px;
    padding-left: 5px;
    text-decoration: none;
    color: black;
    cursor: hand;
    width:99%;
}
.tooltip a:hover
{
    display: block;
    padding-top: 5px;
    padding-left: 5px;
    color: #ffffff;
    background-color: blue;
    text-decoration: none;
}
上面没什么说的,不懂的去http://www.111cn.net/cssdiv/css.html里面查看
最后就是js文件代码了.
function AIToolTip(){this.keyList=new Array();this.currentSelectedItem=null;this.input=null;this.index=-1;this.length=0;this.qurl="data_format.htm";this.hasFocus=false;this.div=document.createElement("DIV");this.div.className="tooltip";this.div.attachEvent("onmouseout",this.Div_OnMouseOut);this.div.attachEvent("onmouseover",this.Div_OnMouseOver);document.body.appendChild(this.div);AIToolTip.prototype.p=this;}
function AIToolTipItem(t,u,c){this.text=t;this.url=u;this.count=c;}
AIToolTip.prototype.OnKeyUp=function(o){var p=AIToolTip.prototype.p;this.input=o;if(!o.getAttribute("hasTip")){o.setAttribute("hasTip",true);o.attachEvent("onblur",this.Input_OnBlur);}switch(event.keyCode){case 38:this.Previous();break;case 40:this.Next();break;case 37:case 39:break;case 13:p.EnterKey();break;default:this.GetValues();}}
AIToolTip.prototype.EnterKey=function(){if(this.currentSelectedItem!=null){this.input.value=this.currentSelectedItem.innerText;}this.Hide();}
AIToolTip.prototype.Show=function(){var tip=this.div.style;var mo=this.input;var top=mo.offsetTop;var hei=mo.clientHeight;var left=mo.offsetLeft;while(mo=mo.offsetParent){top+=mo.offsetTop;left+=mo.offsetLeft;}tip.top=top+20;tip.left=left;tip.display="";this.div.style.posWidth=this.input.offsetWidth;}
AIToolTip.prototype.Hide=function(){this.div.style.display="none";}
AIToolTip.prototype.Input_OnBlur=function(){var p=AIToolTip.prototype.p;if(p.hasFocus){}else{p.Hide();}}
AIToolTip.prototype.Div_OnMouseOut=function(){var p=AIToolTip.prototype.p;p.hasFocus=false;}
AIToolTip.prototype.Div_OnMouseOver=function(){var p=AIToolTip.prototype.p;p.hasFocus=true;}
AIToolTip.prototype.A_MouseMove=function(){var obj=event.srcElement;var p=AIToolTip.prototype.p;if(p.currentSelectedItem!=null){p.UnSelectItem(p.currentSelectedItem);}p.SelectItem(obj);p.input.value=obj.innerText;p.index=obj.getAttribute("index");p.currentSelectedItem=obj;}
AIToolTip.prototype.A_MouseOut=function(){var obj=event.srcElement;var p=AIToolTip.prototype.p;p.currentSelectedItem=obj;}
AIToolTip.prototype.A_OnClick=function(){var obj=event.srcElement;var p=AIToolTip.prototype.p;p.input.value=obj.innerText;p.Hide();}
AIToolTip.prototype.SelectItem=function(obj){obj.style.backgroundColor="blue";obj.style.color="#ffffff";this.index=obj.getAttribute("index");this.currentSelectedItem=obj;}
AIToolTip.prototype.UnSelectItem=function(obj){obj.style.backgroundColor="";obj.style.color="";}
AIToolTip.prototype.Previous=function(){this.index>0?this.index--:0;if(this.currentSelectedItem!=null){this.UnSelectItem(this.currentSelectedItem);}this.SelectItem(this.div.childNodes(this.index));this.currentSelectedItem=this.div.childNodes(this.index);this.input.value=this.div.childNodes(this.index).innerText;}
AIToolTip.prototype.Next=function(){this.index<this.length-1?this.index++:0;if(this.currentSelectedItem!=null){this.UnSelectItem(this.currentSelectedItem);}this.SelectItem(this.div.childNodes(this.index));this.currentSelectedItem=this.div.childNodes(this.index);this.input.value=this.div.childNodes(this.index).innerText;}
AIToolTip.prototype.AddItem=function(text,total){var a=document.createElement("A");a.innerText=text;a.attachEvent("onmousemove",this.A_MouseMove);a.attachEvent("onmouseout",this.A_MouseOut);a.attachEvent("onclick",this.A_OnClick);a.setAttribute("index",this.length);this.keyList.push(text);this.div.appendChild(a);this.length++;}
AIToolTip.prototype.Search=function(k){var a,b;for(var i=0;i<this.length;i++){a=k.toLowerCase();b=this.keyList[i].toLowerCase();if(b.indexOf(a,0)!=-1){if(this.currentSelectedItem!=null){this.UnSelectItem(this.currentSelectedItem);}var obj=this.div.childNodes(i);this.SelectItem(obj);this.div.style.display="";return;}}}
AIToolTip.prototype.ClearAll=function(){this.div.innerHTML="";this.index=-1;this.length=0;while(this.keyList.pop()!=undefined){}}
AIToolTip.prototype.GetValues=function(){var exp=/S/;if(exp.test(this.input.value)){if(this.length>0){this.Search(this.input.value);}else{this.GetValuesFromUrl();}}else{this.Hide();}}
AIToolTip.prototype.GetValuesFromUrl = function()
{this.ClearAll();var p=AIToolTip.prototype.p;var ajax=new ActiveXObject("Msxml2.XMLHTTP.3.0");ajax.open("GET",this.qurl,true);
    ajax.onreadystatechange=function(){if(ajax.readyState==4){var it;eval(ajax.responseText);var i,l;for(i=0,l=list.length;i<l;++i){p.AddItem(list[i].text,list[i].count);}p.Show();}}
    ajax.send();
}

时间: 2024-08-01 15:42:30

Google智能提示的相关文章

JS实现仿google、百度搜索框输入信息智能提示的实现方法

  这篇文章主要介绍了JS实现仿google.百度搜索框输入信息智能提示的实现方法,实例分析了javascript实现智能提示功能的技巧,非常具有实用价值,需要的朋友可以参考下 本文实例讲述了JS实现仿google.百度搜索框输入信息智能提示的实现方法.分享给大家供大家参考.具体如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

vscode-visualstudio code. c++智能提示

问题描述 visualstudio code. c++智能提示 1C 如题怎么能让vscode智能提示C++代码?还有写的过程中有错误会画红线,这些都是怎么做到的?求详细 解决方案 理论上可以写插件实现,但是我觉得还是等官方插件出来比较好.不幸的是,c++ support是low prior的,所以现在还没有. 解决方案二: 特地google了下,根据2月9日官方透露的说法https://visualstudio.uservoice.com/forums/293070-visual-studio

自制基于jQuery的智能提示插件一枚_jquery

目前实现如下功能: 1 最基本需求,根据当前文本框字符取出适配数据  1.1 支持同一页面多个元素调用本插件  1.2 必需的参数是url  1.3 对于连续不断地输入,会把之前的ajax请求全部取消,避免造成服务器无谓的压力(图4)  1.4 最基本调用$("myel").autoCmpt({url:"url"});2 空关键词查询开关(emptyRequest),打开则鼠标点在输入框内即出现提示(当下拉列表用),默认为true(图1)3 支持关联查询,即当前文本

Ajax实现智能提示搜索功能_AJAX相关

一.效果图: 二.实现过程:   思路:  三.部分代码:html: <div id="searchbox"> <div><input type="text" id="txtTitle" /></div> <div id="btnSelect"><a href="javascript:;">Google</a></di

QT 智能提示设置

关于QT的智能提示,有两点: 一:默认只能在Ctrl+Space或打("."会自动转成" ->")的时候会出现. 由于Ctrl+Space默认在我电脑上是输入法的切换.所以一直以为没这个功能,敲代码时特别郁闷. 于是在QT Creator中的Tool->Option中的Environment->Keyborad中把快捷键改成Ctrl+J[vs用习惯了]   二:默认的智能智能提示区别大小写 这个也很郁闷的,敲的快一点总有一个大小写没敲对智能提示就没

asp.net MVC项目中 没有easyui插件的智能提示

问题描述 asp.net MVC项目中 没有easyui插件的智能提示 5C vs2015 中的mvc4项目,已经分别把jQuery.min.js jquery.easyui.min.jseasyui-lang-zh_CN.js依次拖入,写js代码的时候 智能提示只有jquery中的属性和方法 没有easyui的(例如$.messager就出不来智能提示),但是可以正常执行出来插件效果,尝试编辑cshtml.html格式的文件都不提示,尝试把 jquery.easyui.min.js的文件名改为

Google智能路由器OnHub怎么样

  说到路由器相信大家并不陌生,但现在市面上的很多路由器都不尽如人意,有的经常会出现诸如突然断网.网络不稳定等问题,这不与TP-LINK合作推出了他们全新路由器Google OnHub,不知道Google智能路由器OnHub怎么样?下面一起来看看吧. 首先,从设计来说,时尚的设计是 Google OnHub 的一大亮点,因为大多数路由器的外观不佳,很多人不得不将其隐藏在房间的角落中,也许是受到了同类产品例如苹果 AirPort Extreme 的影响,Google OnHub 采用了完全光滑的圆

关于vs2013工具的之智能提示

问题描述 关于vs2013工具的之智能提示 为什么只能提示的代码要ctrl+enter才能选择,感觉好麻烦,能不能只按enter键就可以选择的?还有怎么设置? 解决方案 Tools-import and export settings-reset all settings 是不是安装了resharper之类的第三方VS插件,这些插件也会自动覆盖VS的快捷键 解决方案二: 参考:http://jingyan.baidu.com/article/9158e0006e10d8a254122826.ht

dreamweaver 安装Jquery智能提示_jquery

dreamweaver: 在http://xtnd.us/dreamweaver/jquery网址中下载一个名为jQuery_API.mxp的插件.在Dreamweaver中依次选择"命令"->"扩展管理"->"安装扩展"->"jQuery_API.mxp"命令后,就会自动安装插件了.扩展安装成功后重启dreamweaver,新建空白页面,引入jQuery,然后编写jQuery代码,会发现已经具有自动提示功能