随笔 - 14  文章 - 0  评论 - 0 

JS 暴虐算法查找

 
@dd|ad|fds|d@dd|ad|fds|d@dd|ad|fds|d@
 
var e = [];
    window.onload = function () {
        var O = stocklist.split("@");
        for (var N = 1; N < O.length; N++) {
            var Q = O[N];
            e.push(Q.split("|"));
        }
    };
 
    String.prototype.replaceAll = stringReplaceAll;
    function stringReplaceAll(AFindText, ARepText) {
        var raRegExp = new RegExp(AFindText.replace(/([\(\)\[\]\{\}\^\$\+\-\*\?\.\"\'\|\/\\])/g, "\\$1"), "ig");
        return this.replace(raRegExp, ARepText);
    }
 
    function hint() {
        var index = [];
        var stocks = new String(stocklist);
        var key = $("#text01").val();
        stocks = stocks.replaceAll(key, '#');
        stocks = stocks.replace(/[^@#]/g, "");
        while (stocks.indexOf("#") > 0) {
            var idx = stocks.indexOf("#");
            if (index.indexOf(idx) == -1) {
                index.push(idx);
            }
            stocks = stocks.substring(0, idx) + stocks.substring(idx + 1, stocks.length);
 
        }
        var htm = "";
        $('#slist').html(htm);
        if (index[0] != undefined){
        htm=htm+'<li class="data_abs_tit"><span>股票代码</span><span>股票简拼</span><span>股票简称</span></li>'
        }
        for (var i = 0; i < 10; i++) {
            if (index[i] == undefined) break;
            var idx = index[i];
            var stock = e[index[i] - 1];
            htm = htm + '<li  onclick="fouce(\''+stock[1]+'\')"><a href="http://stock.xx.org/gsda'+stock[1]+'.htm" target="_blank"><span>'+stock[1]+'</span><span> '+stock[2]+'</span><span> '+stock[0]+'</span></a></li>';
        }
         if (index[0] != undefined){
        htm=htm+' <li class="more_search"><a href="http://stock.xx.org/gsda.htm">更多查询结果>></a></li>';
        }
        $('#slist').html(htm);
 
        if (index[0] != undefined) {
            var stock = e[index[0] - 1];
            $('#firstsearch').val(stock[1]);
        } else {
            $('#firstsearch').val('');
        }
    }


来自为知笔记(Wiz)


posted on 2015-08-12 14:08  知识铺  阅读(156)  评论(0编辑  收藏