• autocomplete


    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>js简单的自动完成功能</title>
    <script type="text/javascript">
    var test = function(){
    if(document.getElementById('dis')){
    document.getElementById('dis').parentNode.removeChild(document.getElementById('dis'));
    };
    var arr = ['adsd-in','aads-dd','aasd-in','aa-dd','b-s','c-e','csd'];
    var txt = document.getElementById('txt');
    var re = new RegExp("^"+txt.value+"\w*");
    var div = document.createElement('div');
    div.id = 'dis';
    var innerDiv;
    for(var i=0; i<arr.length; i++){
    if(re.test(arr[i])){
    innerDiv = document.createElement('div');
    innerDiv.className = 'innerDiv';
    innerDiv.appendChild(document.createTextNode(arr[i]));
    innerDiv.onclick = function(){
    this.parentNode.previousSibling.value = this.innerHTML;
    document.getElementById('dis').parentNode.removeChild(document.getElementById('dis'));
    };
    innerDiv.onmouseover = function(){
    this.style.backgroundColor = '#ff0000';
    };
    innerDiv.onmouseout = function(){
    this.style.backgroundColor = '#cccccc';
    };
    div.appendChild(innerDiv);
    };
    };
    if(div.hasChildNodes()){
    txt.parentNode.insertBefore(div, txt.nextSibling || null);
    };
    }
    </script>
    <style type="text/css">
    #dis{
    153px;
    background:#CCCCCC;
    border:1px solid #666;
    height: 60px;
    overflow-y: scroll;
    }
    .innerDiv{
    border-top:1px solid #666;
    }
    </style>
    </head>
    <body>
    <input type="text" id="txt" onkeyup="test();" />
    </body>
    </html>

    本文使用Blog_Backup未注册版本导出,请到soft.pt42.com注册。

  • 相关阅读:
    Selenium RC For Python:教程2
    sql server 获取同比或环比
    C#泛型泛型集合Dictionary<K,V>
    C# FileStream
    c# 强命名的作用
    装箱与拆箱的概念及意义
    SQL Server中Rollup关键字使用技巧
    Javascript内存泄露
    几条复杂的SQL语句
    Group by与having理解
  • 原文地址:https://www.cnblogs.com/zjypp/p/2319523.html
Copyright © 2020-2023  润新知