jQuery 监听 input 输入匹配数据库的值

$("#forecast-index-bus").on("input", function(e) {
    showalert(e.currentTarget.value)
});

// 展示 alert 内容
function showalert(param) {
    var key = param;
    if (key != '') {
        //这里给个全数据
        var xt = check(data, key);

        $('#forecast-index-xc').html('');
        $('#forecast-index-xc').append(xt);
        $('#forecast-index-xc').css('display', 'block');
    } else {
        $('#forecast-index-xc').html('');
    }
}

// 遍历 data 匹配 input 中输入的值
function check(data, key) {
    var out = '';
    for (var i = 0; i < data.length; i++) {
        var s = data[i].indexOf(key);
        if (s == 0 && data[i] != key) {
            // out += "
  • " + data[i] + "
  • "; out += "
  • " + data[i] + "
  • "; } } return out; }

     

    你可能感兴趣的:(Web,FrontEnd,jquery)