zoukankan      html  css  js  c++  java
  • js模糊查询

    <!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>无标题文档</title>
    <script type="text/javascript">
    
    
    function findEach()   
    {   
    var vData= ["name", "sex", "age", "job", "e-mail"]; //查询字符集
    
        var sFind = document.getElementById("input").value;   
        if(sFind==""){   
            alert("Can not be empty.");   
        }   
        
        if(sFind!=""){         
            var nPos;   
            var vResult = [];   
                
            //for(var i = 0; i <= vData.length; i++){   
            for(var i in vData){   
                var sTxt=vData[i]||'';  
                nPos = find(sFind, sTxt);   
                //nPos=sTxt.indexOf(sFind);   
                if(nPos>=0){   
                    vResult[vResult.length] = sTxt;   
                }   
            }   
        
            alert(vResult);   
        }   
    } 
    function find(sFind, sObj)   
    {   
        var nSize = sFind.length;   
        var nLen = sObj.length;    
        var sCompare;   
        
        if(nSize <= nLen ){   
            for(var i = 0; i <= nLen - nSize + 1; i++){   
                sCompare = sObj.substring(i, i + nSize);   
                if(sCompare == sFind){   
                    return i;   
                }   
            }   
        }   
        return -1;   
    }
    
    </script>
    </head>
    
    <body>
    <input id="input" type="text" value="" />   
    <input id="search" type="button" onclick="findEach()" value="Search" /> 
    </body>
    </html>
  • 相关阅读:
    Memcached学习(一)
    了解下SoftReference
    Java Thread UncaughtExceptionHandler
    csdn 不登录浏览全文 chrome 浏览器
    postgresql 主从 patroni
    熔断,限流,降级
    CentOS7.4 源码安装MySQL8.0
    CentOS BIND9安装及配置
    Linux安全之SYN攻击原理及其应对措施
    fping常用参数介绍
  • 原文地址:https://www.cnblogs.com/lyg0126/p/6911050.html
Copyright © 2011-2022 走看看