I have this code-
$(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' }
];
$("#autocomplete").autocomplete({
lookup: fruits,
showNoSuggestionNotice:true,
noSuggestionNotice:"No Result found",
onSelect: function (suggestion) {
alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
},
});
});
In above code, noSuggestionNotice is not working, when there is no suggestion.
Please check API documentation. noSuggestionNotice may be not included in autocomplete function which was available when it was a separate plugin. http://api.jqueryui.com/autocomplete/#entry-examples
Please use this code 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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.