简体   繁体   English

jQuery Ui自动完成-如何从所选值中删除html

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

I am using the jquery ui autocomplete plugin in my page. 我在页面中使用了jQuery ui自动完成插件。

$( "#birds" ).autocomplete({
            //source: sampleData(),
              source: function(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. 字符串是此示例格式的..Akola,India-Akola(AKD)建议列表很好地显示了字符串的实际呈现效果。 But when I select the value the value gets defaulted to the actual html string. 但是,当我选择该值时,该值将默认为实际的html字符串。 How do I make the selected value to have only the string and not the html ? 如何使选定的值仅包含字符串而不包含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. Item.label和Item.value保持不变。.label在建议中显示得很好。.但是我需要使item.value仅包含字符串。

Thanks Yogesh 谢谢Yogesh

try using this.value.text() or else refer to this question. 尝试使用this.value.text()或参考问题。 you may have to play around a little to parse the HTML but these options should work 您可能需要花点时间才能解析HTML,但是这些选项应该可以工作

In order to make this work you should also pass item.value 为了使这项工作,您还应该传递item.value

On select it looks for item.value first and then for item.label 在选择时,它首先寻找item.value ,然后寻找item.label

That way you can leave your select: like that 这样,您就可以选择:

select: function( event, ui ) {

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM