jQuery autocomplete - 获取自动完成输入字段的 id
我有这个 jQuery 代码:
$(".autocomplete").autocomplete('url',{
extraParams: {country: function(){
var id = $(this).attr("id"); // not working
var country = id.replace("uni", "country");
var country_id = $("#"+country).val();
return country_id;
}}
}).result(function(event, item) {
// getNames(item);
});
因为我将有几个带有自动完成字段的 ajax 加载表单, 我需要他们每个人发送适当的附加参数 从相应的表单到服务器。
我试图通过获取输入字段的 id 并使用它来获取将保存必要参数的国家/地区字段的 id 来实现此目的。 id 将采用适当的格式以实现此目的。类似:
uni_1、country_1; uni_2; Country_2
uni 是自动完成字段,country 是附加参数。
我已经意识到 $(this).attr("id") 在自动完成功能中不起作用,就像使用简单的 jQuery 事件一样,并且我还没有找到执行此操作的方法。我尝试使用 toSource 方法来查看自动完成对象,但它似乎不保存字段 id。
因此,如果有人知道如何做到这一点,请分享。
预先非常感谢您。 伊万
i have this jQuery code:
$(".autocomplete").autocomplete('url',{
extraParams: {country: function(){
var id = $(this).attr("id"); // not working
var country = id.replace("uni", "country");
var country_id = $("#"+country).val();
return country_id;
}}
}).result(function(event, item) {
// getNames(item);
});
As I will have several, ajax loaded forms with autocomplete fields,
i need for each of them to send appropriate additional parameters
from the respective form to the server.
I was trying to achieve this by getting the id of the input field and using it to get to the id of the country field which will hold the necessary parameter. The id's would be in the appropriate format to allow for this. Something like:
uni_1, country_1; uni_2; country_2
uni being the autocomplete field, and country the additional parameter.
I have realised that $(this).attr("id") will not work inside the autocomplete, as it would with simple jQuery events, and I have not found a way of doing this. I tried using the toSource method to see the autocomplete object, but it seems that it does not hold the field id.
So if anyone has an idea how this could be done, please share.
Thank you very much in advance.
Ivan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以尝试
You can try