I'm trying to use the jQuery autocomplete plugin. I have an array of IDs that I want to plugin to work on. So, say I have:
var aIds = ["1", "2"];
The examples I see on how to use the plugin looks like this:
$('#1').autocomplete
Is there a way for me to use this autocomplete plugin and my array of ids? The array of ids are coming from a web service.
Also, the autocomplete plugin exposes certain events like select
(see: http://docs.jquery.com/UI/Autocomplete#event-select ). When that happens, how can I tell which element triggered the event (if I am assigning the array of ids dynamically)?
如果要选择一个:
$('#' + aIds.join(', #')).autocomplete();
for(i=0;i<aIds.length;i++)
$('#'+aIds[i]).autocomplete();
Easy, just need to join them together and pass it in. Jquery is great and lets you pass in multiple selectors.
var aIds = ["1", "2"];
// join together your IDS
var selectors = "#" + aIds.join(",#");
// pass in as selectors
$(selectors).autocomplete
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.