【问题标题】:jquery autocomplete devbridge noSuggestionNotice is not workingjquery autocomplete devbridge noSuggestionNotice 不起作用
【发布时间】:2017-02-23 13:23:59
【问题描述】:

我有这个代码-

$(函数() {

var fruits = [
   { value: 'Apple',id: '123',  data: 'Apple' },
   { value: 'Pear', id: '543',   data: 'Pear' },
   { value: 'Carrot', id: '123', data: 'Carrot' },
   { value: 'Cherry', id: '234', data: 'Cherry' },
   { value: 'Banana', id: '543', data: 'Banana' },
   { value: 'Radish', id: '3423', data: 'Radish' }
];

  $("#autocomplete").autocomplete({
        lookup: fruits,
        showNoSuggestionNotice:true,
        noSuggestionNotice:"No Result found",
        onSelect: function (suggestion) {
          alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
        },
  });
});

在上面的代码中,没有建议时,noSuggestionNotice 不起作用。

【问题讨论】:

    标签: javascript jquery search autocomplete


    【解决方案1】:

    请查看 API 文档。 noSuggestionNotice 可能不包含在作为单独插件时可用的自动完成功能中。 http://api.jqueryui.com/autocomplete/#entry-examples

    请使用此代码 http://jsbin.com/nugovolowi/edit?html,js,output

        $( document ).ready(function() {
         var fruits = [
           { value: 'Apple',id: '123',  data: 'Apple' },
           { value: 'Pear', id: '543',   data: 'Pear' },
           { value: 'Carrot', id: '123', data: 'Carrot' },
           { value: 'Cherry', id: '234', data: 'Cherry' },
           { value: 'Banana', id: '543', data: 'Banana' },
           { value: 'Radish', id: '3423', data: 'Radish'}
        ];
    
          $("#mydiv").autocomplete({
                source: fruits,
                onSelect: function (suggestion) {
                  alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
                },
                response: function(event, ui) {
                    // ui.content is the array that's about to be sent to the response callback.
                    if (ui.content.length === 0) {
                        $("#empty-message").text("No results found");
                    } else {
                        $("#empty-message").empty();
                    }
                }
          });
        });
        <!DOCTYPE html>
        <html>
        <head>
          <meta charset="utf-8">
          <meta name="viewport" content="width=device-width">
          <title>JS Bin</title>
        </head>
        <body>
        <script src="https://code.jquery.com/jquery-1.11.3.js"></script>
        <link href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
        <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
        <script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
        <input type="text" id="mydiv"/>
          <div id="empty-message"></div>
        </body>
        </html>

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-09
    • 2015-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多