简体   繁体   中英

How can i add a onclick to resoponse of autocomplete

Here is my script

$('#id').autocomplete({ 
                source: function( request, response ) { 
                    $.ajax({
                        url : path,
                        dataType: "json",
                        data: {
                           id: request.term
                        },
                         success: function( data ) {
                             response( 
                         $.map( data, function( item ) {
                                return {
                                    label: item.id,
                                    value: item.id
                                }  
                            }));
                        } 
                    });
                }, 
                autoFocus: true,
                minLength: 0                       
              });

while clciking on label i need a alert of that value? How can ik make it possible?

You could listen to select event.

$('#id').autocomplete({ 
    source: function( request, response ) { 
      // ...
    }, 
    autoFocus: true,
    minLength: 0,
    select: function(event, ui) {
       alert(ui.item.value);
    }           
});

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM