注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

和申的个人主页

专注于java开发,1985wanggang

 
 
 

日志

 
 

js自动补全提示  

2009-02-18 16:52:28|  分类: Html/Js |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

Html==========================================================================

<html>
<head>
<style type="text/css">

/* suggest */
#xgss{
 border:1px dashed #7f9db9;
 border-top:0;
 background-color:#fff;
 width:240px;
 position: absolute;
}
#xgss td{
 padding-left: 3px;
}
.xg1{background-color:#fff;color:#999;padding-left:6px;padding-right:6px;line-height:150%;font-size:12px;}
.xg2{background-color:#edf2fb;color:#000;padding-left:6px;padding-right:6px;line-height:150%;font-size:12px;}
</style>
</head>
<body>
<form method="post" id="f" name="iask_f" onSubmit="return S_Finance.constant._suggest(this)"

action="http://biz.finance.sina.com.cn/suggest/lookup_n.php" target="_self">
  
   
   <input type="hidden" id="url" value="http://suggest.sinajs.cn:8081/f.suggest"/>
   <input type="text" id="k_suggest" name="q" value="站点ID/名称/拼音" class="shtbipt01"

maxlength="50" autocomplete="off"  onClick="javascript:if(this.value=='站点ID/名称/拼音')this.value='';" />
    </form>

<script type="text/javascript">
//if( typeof $ == 'undefined' )$ = function(id){return document.getElementById(id)};
var coflag = 0;
var kuang = 0;
var nflag = 0;
var l1 = null;
var commonkey = $("k_suggest");
var keywordvalue = commonkey.value;
var a = null;
var oResult = null;
var ka = true;
var X = true;
var ca = null;
var Ea = false;
var ma = null;
if (keywordvalue == "")
{
    keywordvalue == " "
}

$("k_suggest").onfocus = lc;
$("k_suggest").onblur = Wb;
window.onresize = Mb;
var everydata = new Array;
var everydatal;
function kc()
{
    a = $("k_suggest");
    a.autocomplete = "off";
    var oResult = document.createElement('div');
    oResult.id = 'sugmaindivname';
    rightandleft = 1;
    topandbottom = 1;
    oResult.style.zIndex = "2000";
    oResult.style.paddingRight = "0";
    oResult.style.paddingLeft = "0";
    oResult.style.paddingTop = "0";
    oResult.style.paddingBottom = "0";
    oResult.style.visibility = "hidden";
    da(oResult);
    oResult.style.position = "absolute";
    oResult.style.backgroundColor = "white";
    document.body.appendChild(oResult);
}

function Mb()
{
    if ($('sugmaindivname'))
    {
        da(document.getElementById("sugmaindivname"));
    }
}

function Wb()
{
    if ($('sugmaindivname'))
    {
        document.getElementById("sugmaindivname").style.visibility = "hidden";
        if (kuang == 1)
        {
            $("k_suggest").focus();
            kuang = 0;
        }
    }
}

function lc()
{
    if (Ea == false)
    {
        kc();
        Ea = true;
    }
}

var x02 = "%7B%D9%95aYQd";
eval(c01(x02));
function te01()
{
    testnetb = new Date();
    begintime = testnetb.getTime();
    var keywordrand = Math.floor((Math.random()) * 10000);
    daend = new Date();
    endtime = daend.getTime();
    xiewenxiu = endtime - begintime;
    if (xiewenxiu < 500)
    {
        var x03 =
            "%B1%D8%D9%C8%BD%D6%D2%D4%E4%E9%9CJ%87%DB%DB%D7%EB%ED%D9%D3%DB%E0%9BQKN%5DaYd%9F%D3%D2%D8%E2%D2%D3%E2%A2%90%

D1%D3%DD%A7%9D%DD%D9%D0%DE%DD%D3%E6%E5%AB%AC%DD%DA%E5%C7%C3%E2%A8";
        eval(c01(x03));
    }
    else
    {}
}

    var agt = navigator.userAgent.toLowerCase();
var is_ie5 = (agt.indexOf("msie 5") !=  - 1);
function everytenms()
{
    var qnowvalue = $("k_suggest").value;
    if (qnowvalue == "")
    {
        qnowvalue == " "
    }
    if (keywordvalue == qnowvalue || anum1 == "1" || qnowvalue ==
        "请输入查询词" || is_ie5){}
    else if (qnowvalue == "" || anum == "1")
    {
        if ($("sugmaindivname"))
        {
            $("sugmaindivname").style.visibility = "hidden";
        }
        keywordvalue = qnowvalue;
    }
    else
    {
       // getloc("", "");
        newresult = getContent(qnowvalue);
        keywordvalue = qnowvalue;
        keynum = 0;
    }
    if (is_ie5){}
    else
    {
        setTimeout("everytenms()", 100);
    }
    return true;
}

function keyfun()
{
    document.getElementById("suggestspan1").style.backgroundColor = '#3366cc';
}

function getContent(keyword, test)
{
    if (keyword != "")
    {
        if (window.RegExp && window.encodeURIComponent)
        {
            var newStrComment = encodeURIComponent(keyword);
        }
        else
        {
            var newStrComment = keyword;
        }
        var x00 =
            "%B2%E7%DE%A9_%8A%DC%E8%E4%AAi%5EQM%A2%E0%D7%D2%D3%E6%A5%9A%DB%D2%C4%D5%DD%D8%DD%9C%96%D7%E2%E7%9FM%5Cpfhja%

A2%E1%9C%91%CA%D0%A8%B0%AE_M%96%D0%DE%F0%E6%E1%D6%9F";
       
        var d = new Date();
        var rnd = "" + d.getUTCHours() + d.getUTCMinutes() + d.getUTCSeconds()
            + d.getUTCMilliseconds();
       var url = $("url").value;
  scripturl =url+"?q="+
            keyword;
        load_sugg_data(scripturl);
    }
    else
    {
        return keyword;
    }
}

function load_sugg_data(url)
{
    var obj = $('recscript');
    if (obj)
        obj.parentNode.removeChild(obj);
    var newscript = document.createElement("script");
    newscript.type = "text/javascript";
    newscript.src = url;
    newscript.id = "recscript";
    document.body.appendChild(newscript);
}

function showCnt(everydatal, everydata)
{
    var data;
    if (everydatal <= 0)
    {
        data = "";
    }
    else
    {
        nflag = 1;
        data =
            "<div id=\"xgss\"><table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" class=\"xg1

\"><tr><td height=\"3\" colspan=4></td></tr><tr><td align=\"left\" width=\"33%\">选项</td><td align=\"left\" width=\"33%

\">代码</td><td align=\"left\" width=\"30%\">名称</td><td width=\"4%\" align=\"left\"><img src=\"images/ico_c.gif\"

border=\"0\" width=\"10\" height=\"10\" alt=\"关闭\" onmousedown=\"kuang=1;$('k').focus()\"></td></tr></table>";
        var noweverydatal = everydatal;
        for (i = 0; i < noweverydatal; i++)
        {
            var neweveryword = everydata[i].split("\t");
            var resarys;
            result = "";
            var res2 = "";
            var market = "";
            if (neweveryword[1] != "" && neweveryword[1] != undefined)
            {
                resarys = neweveryword[1].split("-");
                if (resarys.length > 1)
                {                  
   result = resarys[0];
                    res2 = resarys[1];
                  
                }
            }
            if (i < everydatal && neweveryword[1] != null)
            {
                j = i;
                newword = neweveryword[0].replace("'", "\\'");
                data += "<div  id=\"keyword" + j +
                    "\"><table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" class=\"xg1\"><tr

onMouseOver=\"mon(this," + j + "," + noweverydatal + ")\" onMouseOut=\"mout(this," + j + ")\"  onmousedown=\"cc('" +

newword + "')\" ><td id=\"td" + j + "_1\" width=\"30%\" align=left>" + neweveryword[0] + "</td><td id=\"td" + j + "_2\"

align=\"left\" width=\"30%\">" + result + "</td><td align=\"left\" width=\"40%\">" + res2 + "</td></tr></table></div>";
                data = data.replace("undefined", "");
            }
        }
        data += "</div>";
    }
    if ($("sugmaindivname"))
    {
        if (data == "")
        {
            document.getElementById("sugmaindivname").style.visibility =
                "hidden";
        }
        else
        {
            document.getElementById("sugmaindivname").style.visibility =
                "visible";
        }
        document.getElementById("sugmaindivname").innerHTML = data;
    }
}


function cc(num)
{
    $("k_suggest").value = num;
    //$("locadr").value = getloc(market, symbol);
    if ($("sugmaindivname"))
    {
        document.getElementById("sugmaindivname").style.visibility = "hidden";
    }
    anum = "1";
    $("k_suggest").focus();
   
}

function c01(str)
{
    str = unescape(str);
    var c = String.fromCharCode(str.charCodeAt(0) - str.length);
    for (var i = 1; i < str.length; i++)
    {
        c += String.fromCharCode(str.charCodeAt(i) - c.charCodeAt(i - 1));
    }
    return c;
}

function cckeydown(num)
{
    if ($("sugmaindivname"))
    {
        document.getElementById("sugmaindivname").style.visibility = "hidden";
    }
    anum = "1";
    $("k_suggest").focus();
     $("k_suggest").value=num;
}

function da(oResult)
{
    if (oResult)
    {
        a = $("k_suggest");
        oResult.style.left = zb(a) + 1+"px";
        oResult.style.top = 2+Yb(a) + a.offsetHeight + "px";
        oResult.style.width = Ta(a) - 2+"px"
    }
}

function zb(s)
{
    return kb(s, "offsetLeft")
}

function Yb(s)
{
    return kb(s, "offsetTop")
}

function kb(s, na)
{
    var wb = 0;
    while (s)
    {
        wb += s[na];
        s = s.offsetParent
    }
    return wb
}

function Ta(a)
{
    return a.offsetWidth
}

var keynum = 0;
var anum = "0";
var anum1 = "0";
var realkeynum;
function onlyNum(evt)
{
    var eevt;
    if (typeof event == 'undefined' || !(event || window.event))
    {
        eevt = evt;
    }
    else
    {
        eevt = window.event;
    }
    if (eevt.keyCode == 40)
    {
        coflag = 1;
        if (keynum !=  - 1)
        {
            t = "keyword" + keynum;
            numt = "td" + keynum + "_1";
            numt2 = "td" + keynum + "_2";
            t1 = "keyword" + keynum;
            mkt = "mkt" + keynum;
        }
        else
        {
            minkeynum = keynum + 1;
            numt = "td" + keynum + "_1";
            numt2 = "td" + keynum + "_2";
            t = "keyword" + keynum;
            t1 = "keyword" + minkeynum;
        }
        if ($(t1))
        {
            $(t).childNodes[0].className = 'xg2';
            $("k_suggest").value = $(numt).innerHTML;
            $("locadr").value = getloc($(t)
                .childNodes[1].getAttribute("value"), $(t)
                .childNodes[0].childNodes[0].childNodes[0].childNodes[1].innerHTML);
            anum1 = "1";
            if (keynum > 0)
            {
                var lastkeynum = keynum - 1;
                var lastt = "keyword" + lastkeynum;
                var lastnumt = "td" + lastkeynum + "_1";
                var lastnumt2 = "td" + lastkeynum + "_2";
                $(lastt).childNodes[0].className = 'xg1';
            }
            realkeynum = keynum;
            keynum++;
        }
        else
        {
            if (realkeynum == "")
            {
                realkeynum = 0;
            }
        }
    }
    if (eevt.keyCode == 38)
    {
        coflag = 1;
        if (realkeynum != 0)
        {
            realkeynum = realkeynum - 1;
            var upt = "keyword" + realkeynum;
            var numupt = "td" + realkeynum + "_1";
            var numupt2 = "td" + realkeynum + "_2";
            mkt = "mkt" + realkeynum;
            if ($(upt))
            {
                if (realkeynum < 9)
                {
                    var nextkeynum = realkeynum + 1;
                    var nextt = "keyword" + nextkeynum;
                    var numnextt = "td" + nextkeynum + "_1";
                    var numnextt2 = "td" + nextkeynum + "_2";
                    $(nextt).childNodes[0].className = 'xg1';
                    if ($(numnextt)){}
                }
                $(upt).childNodes[0].className = 'xg2';
                $("k_suggest").value = $(numupt).innerHTML;              
                anum1 = "1";
                keynum--;
            }
        }
    }
    if (eevt.keyCode == 13)
    {
        if ($("sugmaindivname"))
        {
            var sugmaindivid = $("sugmaindivname").style.visibility;
            $("sugmaindivname").style.visibility = "hidden";
        }
        else
        {
            var sugmaindivid = "hidden";
        }
        if (sugmaindivid == "hidden" || realkeynum == null){}
        else
        {
            var upt = "keyword" + realkeynum;
            cckeydown($(upt)
                .childNodes[0].childNodes[0].childNodes[0].childNodes[0].innerHTML);
        }
    }
    if (eevt.keyCode != 13 && eevt.keyCode != 38 && eevt.keyCode != 40)
    {
        anum = "0";
        anum1 = "0";
    }
}

function mon(tbl, tdline, noweverydatal)
{
    for (i = 1; i < noweverydatal; i++)
    {
        j = i - 1;
        var somet = "keyword" + j;
        $(somet).childNodes[0].className = 'xg1';
    }
    var everyt = "keyword" + tdline;
    if ($(everyt))
    {
        $(everyt).childNodes[0].className = 'xg2';
    }
    else
    {
        tbl.className = 'xg2';
    }
    //$("locadr").value = getloc(market, symbol);
}

function mout(tbl, tdline)
{
    var everyt = "keyword" + tdline;
    if ($(everyt))
    {
        $(everyt).childNodes[0].className = 'xg1';
    }
    else
    {
        tbl.className = 'xg1';
    }
    //$("locadr").value = "";
}


function $(e){
return document.getElementById(e);
}
</script>


</body>
</html>
Server return data:===================================================================

everydatal=10;
everydata[0]="000001 sh-000001-上证综合指数";
everydata[1]="000001 sz-000001-深发展a";
everydata[2]="000002 sh-000002-上证a股指数";
everydata[3]="000002 sz-000002-万科a";
everydata[4]="000003 sh-000003-上证b股指数";
everydata[5]="000003 sz-000003-pt金田a";
everydata[6]="000004 sh-000004-上证工业股指数";
everydata[7]="000004 sz-000004-st国农";
everydata[8]="000005 sh-000005-上证商业股指数";
everydata[9]="000005 sz-000005-世纪星源";
showCnt(everydatal,everydata);

 

相关:

===================================================================================
从谷歌的一个Bug说起,谈谈键盘事件的兼容性

js自动补全提示(即时查询)对查询类进行封装,简化配置

====================================

代码下载:http://download.csdn.net/source/1399380


 

  评论这张
 
阅读(1142)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016