jQuery 自动完成功能 - 不确定如何获取字段中的当前文本
目前,我的自动完成 jQuery 代码中有类似这样的内容:
$("input#autocomplete").autocomplete({
source: "/problems/get_categories_ajax.php?category="+$(this).data("autocomplete", ui.item.autocomplete),
delay: 0,
minLength: 0,
autoFocus: true,
select: function (event, ui) {
$("#user_id").val(ui.item.id);
$(this).data("user_id",ui.item.id);//Store arbitrary data associated with the specified element
$(this).data("username",ui.item.value);//Store arbitrary data associated with the specified element
},
selectFirst: true,
autoFill: true,
mustMatch: true
})
.bind("blur",function() {
var autocomplete = $(this).data("autocomplete");
$(this).val(autocomplete);
$("#autocomplete").val(autocomplete);
});
但在尝试在此处构造 AJAX 调用时,出现无法使用 ui 变量的错误:source: "/problems/get_categories_ajax.php?category="+$ (this).data("autocomplete", ui.item.autocomplete),
如何从表单中获取值并传递到那里?
谢谢!
I currently have something like this in my autocomplete jQuery code:
$("input#autocomplete").autocomplete({
source: "/problems/get_categories_ajax.php?category="+$(this).data("autocomplete", ui.item.autocomplete),
delay: 0,
minLength: 0,
autoFocus: true,
select: function (event, ui) {
$("#user_id").val(ui.item.id);
$(this).data("user_id",ui.item.id);//Store arbitrary data associated with the specified element
$(this).data("username",ui.item.value);//Store arbitrary data associated with the specified element
},
selectFirst: true,
autoFill: true,
mustMatch: true
})
.bind("blur",function() {
var autocomplete = $(this).data("autocomplete");
$(this).val(autocomplete);
$("#autocomplete").val(autocomplete);
});
but I get the error that I can't use the ui variable when trying to construct the AJAX call here: source: "/problems/get_categories_ajax.php?category="+$(this).data("autocomplete", ui.item.autocomplete),
How can I get the value from the form to pass in there?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要手动将其添加为参数。它将自动附加为
term
。如果您需要指定不同的参数名称,那么您应该声明一个自定义
source
函数:(来源:http://jqueryui.com/autocomplete/#remote-jsonp)
You don't need to add it manually as a parameter. It would be automatically appended as
term
.If you need to specify a different parameter name, then you should declare a custom
source
function:(Source: http://jqueryui.com/autocomplete/#remote-jsonp)