jquery ui autocomplete _renderItem seems to interfere with select event

前端 未结 1 551
[愿得一人]
[愿得一人] 2021-01-04 18:36

My select event doesn\'t work if I use _renderItem. If I comment out the last block of code where I call _renderItem, the select event works. When I use _renderItem, the se

1条回答
  •  孤街浪徒
    2021-01-04 18:56

    I believe this is because you are not wrapping the item in an anchor (a) tag. Update your code to wrap the img in an anchor and it'll work fine:

    $.ui.autocomplete.prototype._renderItem = function(ul, item) {
      return $("
  • ") .data("item.autocomplete", item) .append('' + item.label + '') .appendTo( ul ); };

    Here are some examples that might help:

    • Example without including an a tag in the markup generated in _renderItem (select is broken here like in your question): http://jsfiddle.net/MaLqe/

    • Example with an a tag in the generated markup: http://jsfiddle.net/3zSMG/

    0 讨论(0)
提交回复
热议问题