jQuery UI autocomplete select event not working with mouse click

前端 未结 9 866
星月不相逢
星月不相逢 2020-12-28 15:09

I have a list of links, and I have this search box #reportname. When the user types in the search box, autocomplete will show the text of the links in a list.



        
9条回答
  •  忘掉有多难
    2020-12-28 15:44

    To your 2nd question: "How can I differentiate between select events that are triggered by keyboard with the ones triggered by mouse?"

    The event object in the jQuery UI events would include a .originalEvent, the original event it wrapped. It could have been wrapped multiple times though, such as in the case of Autocomplete widget. So, you need to trace up the tree to get the original event object, then you can check for the event type:

    $("#reportname").autocomplete({
        select: function(event, ui) {
            var origEvent = event;
            while (origEvent.originalEvent !== undefined)
                origEvent = origEvent.originalEvent;
            if (origEvent.type == 'keydown')
                $("#reportfind").click();
        },
        ...
    });
    

提交回复
热议问题