How to get the user inputted custom value and the

2019-09-01 05:25发布

问题:

I'm using jQuery autocomplete to populate suggestion for a textbox and it works perfectly. Trouble is when user intends to enter their own custom value. Below given code gives me the selected value:

 change: function(event, ui) {

    if (ui.item) 
    {
        values=values+ui.item.value;
    }
}

My issue far more complicated as user intends to add their own custom value which means I have to to grab the exact value the user has typed in. As per my requirement I need to add a special character like a ? (question mark) after every selected value from the autocomplete suggestion which has to used to do an exact search. If the user was limited to select only from the autocomplete it would have been way too easy and I could append that character inside the if. But how can I differentiate between custom value and suggested value? How can I attain this?

回答1:

Simply make a new dropdown div, and have a script:

b.value = a.value

to constantly replicate the value typed in. Run the autocorrect on the second value but not the first. Then add an event listener to the second event that changes

a.value = b.value

Once clicked.