Apply jQuery autocomplete to cloned element

后端 未结 2 1897
攒了一身酷
攒了一身酷 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: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.

提交回复
热议问题