jQuery 自动完成“附带损害”在其他领域
我有一个 jquery 自动完成字段工作正常,后面跟着一个日期输入字段。每当用户从自动完成列表中选择一个项目时,它都会正确选择该项目并触发 result(),但它也会在我的日期字段中创建“附带损害”,将所选自动完成项目的 ID 插入其中。这是其中一种情况,但我在其他情况下也注意到了这一点,有时如果其他输入字段位于自动完成字段之前或之后,并不重要。另外,如果有 3 个(任意数量)其他字段,则所有这三个字段都将插入自动完成项目 ID。
这是不受欢迎的行为,我需要摆脱它。 有人吗?
这是代码:
$("#Clients").focus().autocomplete('<%=Url.Action("GetClients", "Client") %>', {
dataType: 'json',
parse: function(data) {
var rows = new Array();
for (var i = 0; i < data.length; i++) {
rows[i] = { data: data[i], value: data[i].ClientName, result: data[i].ClientName };
}
return rows;
},
formatItem: function(row, i, n) {
return row.ClientName;
},
width: 300,
minChars: 0,
max: 0,
delay: 50,
cacheLength: 10,
selectFirst: true,
selectOnly: true,
mustMatch: true
});
$("#Clients").result(function(event, data, formatted) {
if (data) {
$(this).parent().next().find("input").val(data["client_id"]);
if (data["ClientName"] && data["client_address1"] && data["client_postcode"] && data["client_postname"]) {
$("#ClientDetails").html(
"<li class=\"clientNumber\">Client Id: " + data["client_ClientNumber"] + "</li>" +
"<li>" + data["ClientName"] + "</li>" +
"<li>" + data["client_address1"] + "</li>" +
"<li>" + data["client_postcode"] + data["client_postname"] + "</li>"
);
}
else {
$("#ClientDetails").html(
"<li class=\"clientNumber\">Client Id: " + data["client_ClientNumber"] + "</li>" +
"<li>" + data["ClientName"] + "</li>");
}
}
});
I have a jquery autocomplete field working fine followed by a date input field. Whenever a user selects an item from autocomplete list it correctly selects the item and fires result() but it also creates "collateral damage" in my date field, inserting ID of the selected autocomplete item into it. This is one case of it but I also noticed it in other occasions, sometimes if other input fields are before autocomplete field or behind, doesn't really matter. Also If there are 3 (any number) other fields all three would be inserted the autocomplete item ID.
It is undesired behaviour and I need to get rid of it.
Anyone?
Here's the code:
$("#Clients").focus().autocomplete('<%=Url.Action("GetClients", "Client") %>', {
dataType: 'json',
parse: function(data) {
var rows = new Array();
for (var i = 0; i < data.length; i++) {
rows[i] = { data: data[i], value: data[i].ClientName, result: data[i].ClientName };
}
return rows;
},
formatItem: function(row, i, n) {
return row.ClientName;
},
width: 300,
minChars: 0,
max: 0,
delay: 50,
cacheLength: 10,
selectFirst: true,
selectOnly: true,
mustMatch: true
});
$("#Clients").result(function(event, data, formatted) {
if (data) {
$(this).parent().next().find("input").val(data["client_id"]);
if (data["ClientName"] && data["client_address1"] && data["client_postcode"] && data["client_postname"]) {
$("#ClientDetails").html(
"<li class=\"clientNumber\">Client Id: " + data["client_ClientNumber"] + "</li>" +
"<li>" + data["ClientName"] + "</li>" +
"<li>" + data["client_address1"] + "</li>" +
"<li>" + data["client_postcode"] + data["client_postname"] + "</li>"
);
}
else {
$("#ClientDetails").html(
"<li class=\"clientNumber\">Client Id: " + data["client_ClientNumber"] + "</li>" +
"<li>" + data["ClientName"] + "</li>");
}
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对我来说,这条线
看起来有点可疑。
ID 为“Clients”的输入控件
For me this line
looks a bit dubious.
input control with the ID "Clients"