开发者

Jquery Ui Autocomplete - How to remove the html from the selected value

I am using the jquery ui autocomplete plugin in my page.

$( "#birds" ).autocomplete({
            //source: sampleData(),
              source: functi开发者_开发问答on(request, response) {
              response(data(request.term));

        },


    enter code here
            minLength: 3,
            select: function( event, ui ) {
                //alert(ui.item.label);

                log( ui.item ?
                    "Selected: " + ui.item + " aka " + ui.item.id :
                    "Nothing selected, input was " + this.value );
            }
        });

The response call back gets a string array as its return value. the string is of this sample format ..Akola,India-Akola(AKD) The suggestion list comes up fine with the actual rendered from the string. But when I select the value the value gets defaulted to the actual html string. How do I make the selected value to have only the string and not the html ?

Item.label and Item.value remain the same..label shows up fine in suggestion.. but I need to make the item.value contain only the string.

Thanks Yogesh


try using this.value.text() or else refer to this question. you may have to play around a little to parse the HTML but these options should work


In order to make this work you should also pass item.value

On select it looks for item.value first and then for item.label

That way you can leave your select: like that

select: function( event, ui ) {

    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜