Apply jQuery autocomplete to cloned element

后端 未结 2 1896
攒了一身酷
攒了一身酷 2021-01-13 21:15

I am using jQuery autocomplete which is working fine with existing element but not with dynamically added element.

Here is my autocomplete code (Which I have chang

相关标签:
2条回答
  • 2021-01-13 21:48

    You can use 'live', although these days you should be using the 'on' method.

    See this thread for working examples (including one that uses 'on' if you drill down in to some of the hidden answers): Bind jQuery UI autocomplete using .live()

    Cheers Matt

    0 讨论(0)
  • 2021-01-13 21:50

    You can't use 'live' on autocomplete, as far as I know.

    Place your autocomplete options in a function that expects the field as parameter, on which you want to apply the autocomplete method.

    function enable_autocomplete(InputField) {
        $(InputField).autocomplete({
            source: availableTags
        });
    }
    

    Then, after cloning the field, call this function with the cloned field.

    enable_autocomplete(ClonedField);
    

    I've written you an easy example, what makes it much easier to understand what I am trying to say ;-)

    Edit: I've written another example based on the combobox example from jQueryUIs website.

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