-2

我正在使用 select2.js 突出显示作为响应接收的特定 li。

var cityCounter = -1;
var sul = $('.select2-search-choice');
$(".select2-input").keyup(function (e) {
    // TODO CODE
    // console.log($(this).val());
    var kKey = e.which;
    if (kKey === 40) {
        var sli = sul.$('li');
        var slen = sli.length;
        ++cityCounter;
        if (cityCounter > slen - 1) cityCounter = 0
        //sli[suggDateCounter].getElementsByTagName('a')[0].focus();
        for (k = 0; k < slen; k++) {
            sli[k].getElementsByTagName('a')[0].style.background = '#F9F9F9';
        }
        sli[cityCounter].getElementsByTagName('a')[0].style.background = '#CCCCCC';
        //alert(suggcounter);
        //console.log("suggDateCounter: "+suggDateCounter);
        if (cityCounter != (slen - 1)) // Current isn't last
        sli[slen - 1].getElementsByTagName('a')[0].style.background = '#000000';

    }
    if (ajaxInProgress == false) {
        if ($(this).val().trim().length >= 3) {
            ajaxInProgress = true;
            $(".select2-results").html("");
            $.ajax({
                url: '<?php echo $this->registry->siteurl; ?>/index.php',
                data: 'route=index/get_home_cities/' + $(this).val(),
                type: 'GET',
                success: function (response) {
                    $(".select2-results").append(response);
                    //$(".select2-results").append("<li>UAE</li>");
                    ajaxInProgress = false;
                }
            });
        }
    }
}); 

问题是我收到一个类型错误,我不知道为什么会收到这个错误。

         TypeError: sul.$ is not a function 
4

1 回答 1

2

我想你的意思是

 var sli = sul.find('li');
于 2013-11-06T11:33:58.093 回答