Jquery Ui 自动完成 - 如何从所选值中删除 html
我在我的页面中使用 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 );
}
});
响应回调获取一个字符串数组作为其返回值。 该字符串的示例格式为 ..Akola,India-Akola(AKD) 建议列表与字符串的实际渲染效果很好。 但是当我选择该值时,该值将默认为实际的 html 字符串。 如何使所选值仅包含字符串而不包含 html ?
Item.label 和 Item.value 保持不变..标签在建议中显示良好.. 但我需要使 item.value 仅包含字符串。
谢谢 约格什
I am using the jquery ui autocomplete plugin in my page.
$( "#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.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用 this.value.text() 或参考 this问题。你可能需要花点时间来解析 HTML,但这些选项应该可以工作
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
为了使这项工作正常进行,您还应该
在选择时传递 item.value ,它首先查找 item.value,然后查找 item.label
你可以留下你的选择的方式:像这样
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