jQuery 多表单输入和多源
我有 2 个独立的表单字段,我想在其中使用 jQuery 的自动完成功能。目前,我定义了 2 个单独的函数以及用于字段输入的 2 个不同标识符。目前只有一部作品。这是我的代码的样子
form.cfm
<script type="text/javascript">
$(function() {
$("#name").autocomplete({
source: function(request, response) {
$.ajax({
url: "cfc/cfc_auto1.cfc?method=getCustomerNames&returnformat=json",
dataType: "json",
data: {
nameCustomerSearchString: request.term,
nameid: request.term,
Comp: $('#Comp').val(),
maxRows: 25
},
success: function(data) {
response(data);
}
});
}
});
});
</script>
<script type="text/javascript">
$(function() {
$("#name2").autocomplete({
source: function(request, response) {
$.ajax({
url: "cfc/cfc_auto2.cfc?method=getNames&returnformat=json",
dataType: "json",
data: {
nameSearchString: request.term,
nameid: request.term,
Comp: $('#Comp').val(),
maxRows: 25
},
success: function(data) {
response(data);
}
});
}
});
});
<form...
<input id="Name" name="Contact" value="" size="70" />
.../form>
<form...
<input id="Name2" name="Contact" value="" size="70" />
.../form>
我可以显示 cfc,但它们在单独使用时都可以工作。除了查询之外,它们是相同的。 Auto1.cfc 查询与 Auto2.cfc 不同的表。
I have 2 separate form fields where I would like to utilize jQuery's autocomplete function. Currently I have 2 separate functions defined as well as 2 different identifiers for the input for fields. Currently only one works. Here is what my code looks like
form.cfm
<script type="text/javascript">
$(function() {
$("#name").autocomplete({
source: function(request, response) {
$.ajax({
url: "cfc/cfc_auto1.cfc?method=getCustomerNames&returnformat=json",
dataType: "json",
data: {
nameCustomerSearchString: request.term,
nameid: request.term,
Comp: $('#Comp').val(),
maxRows: 25
},
success: function(data) {
response(data);
}
});
}
});
});
</script>
<script type="text/javascript">
$(function() {
$("#name2").autocomplete({
source: function(request, response) {
$.ajax({
url: "cfc/cfc_auto2.cfc?method=getNames&returnformat=json",
dataType: "json",
data: {
nameSearchString: request.term,
nameid: request.term,
Comp: $('#Comp').val(),
maxRows: 25
},
success: function(data) {
response(data);
}
});
}
});
});
<form...
<input id="Name" name="Contact" value="" size="70" />
.../form>
<form...
<input id="Name2" name="Contact" value="" size="70" />
.../form>
I can show the cfc's but they both work when used by themselves. They are identical except for the query. Auto1.cfc queries a different table then Auto2.cfc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,输入字段的
name
属性与其id
属性不同。此外,两个输入字段共享相同的
name
属性。尝试做:我认为它试图获取错误的字段。
From what I see the
name
attribute of the input fields is different from theirid
attribute.Also the two input fields share the same
name
attribute. Try doing:I think it was trying to get the wrong fields.