【问题标题】:jquery auto-complete displaying search box empty in IE11 and chromejquery自动完成在IE11和chrome中显示搜索框为空
【发布时间】:2014-08-26 16:37:44
【问题描述】:

我正在使用 jquery 自动完成功能创建搜索栏。

这是我的自动完成代码:

$('#search_bar input#search_box').autocomplete({
        source: function( request, response ) {
        $.ajax({
            url: "service/search.php",
            type: "POST",
            data: {action:'getSuggest',categoryId:$('#search_bar #selectSearch').val(),searchText:request.term},
            dataType: "json",
            cache: false,
            success: function( data ) {
            response( $.map( data['0'], function( Convalue ) {
                return {
                label: Convalue['name'],
                value: Convalue['name'],
                id: Convalue['ID']
                }
            }));
            },
            error: function (e,a,b) {
            jAlert('error in searching products'+e,'Failed');
            }
        });
        },
        cacheLength: 0,
        minLength: 1,
        select: function( event, ui ) {
        event.preventDefault();     
        $('#search_bar input#search_box').val();
        if(ui.item)
        {
            var categoryId=$('#search_bar #selectSearch').val();
            if(categoryId=='0'){
            if(ui.item.id=='1')
                location.replace('custom-granule.php');
            else if(ui.item.id=='2')
                location.replace('custom-raw.php');
            else
                location.replace('product-info.php?id='+ui.item.id);
            }
            else if(categoryId=='1')
            location.replace('product-symptom.php?id='+ui.item.id);
            else if(categoryId=='2')
            location.replace('product-pattern.php?patternId='+ui.item.id);
            else
            location.replace('product-category.php?id='+ui.item.id);
        }
        else {
            jAlert("Nothing selected, input was " + this.value);
        }
        }
    });

现在我的问题是:IE 和 Chrome 在搜索时显示警报消息“搜索框为空”。 IE 和 chrome 在显示此警告框时不一致。有时显示,有时不显示。 FF好像还可以。

【问题讨论】:

    标签: jquery autocomplete jquery-autocomplete


    【解决方案1】:

    搜索栏输入#search_box

    这个带有# 运算符的选择器可能不会在每个浏览器中都选择正确的元素。您可以按 F12 在 chrome 控制台中测试它

    【讨论】:

    • 我认为这不是选择器的问题。因为,有时它会正确搜索,如果我重复搜索超过 10 次,那么它会在 IE 和 chrome 中显示“空搜索”。
    • 我昨天在我的 mvc 项目中看到了相同的行为,而不是我只是从标记名中删除 # 字符,我将 uniq id 写入元素,它对我有用。我不确定,但试试这个
    猜你喜欢
    • 2013-08-20
    • 1970-01-01
    • 2017-07-18
    • 2023-03-18
    • 1970-01-01
    • 2023-03-05
    • 2019-05-05
    • 2015-08-18
    • 1970-01-01
    相关资源
    最近更新 更多