[英]jQuery Autocomplete not working for Dynamic Form Fields
嘿伙计......我回来了另一个问题......
我在表单字段上使用jquery自动完成。 有用!
问题是,然后动态我向表单添加另一行,但事实并非如此。 是的,我一直将新字段的ID切换为新字段。
原始= exampassed1动态添加= exampassed2,exampassed3等等......
我已经添加了他们的jQuery等价物
$("#exampassed1").autocomplete({
source: "exams.php",
minLength: 2
});
$("#exampassed2").autocomplete({
source: "exams.php",
minLength: 2
});
等等...
我认为问题是jQuery没有识别动态添加的元素,它只读取加载中存在的元素...
有没有办法我们可以戳jquery处理程序来读取这些新添加的元素?
我听说过绑定和实时功能,虽然我找不到实现这些功能的方法......
这里有任何小/全帮助非常感谢...干杯!
我使用的jQuery
$().ready(function() {
$("#autonco").autocomplete({
source: "nco.php",
minLength: 2
});
$("#autonco1").autocomplete({
source: "nco.php",
minLength: 2
});
$("#autonco2").autocomplete({
source: "nco.php",
minLength: 2
});
$("#exampassed1").autocomplete({
source: "exams.php",
minLength: 2
});
$("#exampassed2").autocomplete({
source: "exams.php",
minLength: 2
});
});
那里的代码已经存在......
<td align="center" valign="top">
<input type="text" id="exampassed1" name="exam[]" />
</td>
动态添加的代码......
<td valign="top" align="center">
<input id="exampassed2" name="exam[]" type="text">
</td>
任何指针也很感激!
非常感谢!
以下是我使用的代码。 解决了!
$().ready(function() {
$("#exampassed1").autocomplete({
source: "exams.php",
minLength: 2
});
$("#exampassed2").live('focus', function() {
$("#exampassed2").autocomplete({
source: "exams.php",
minLength: 2
});
});
});
干杯!
在收到前一个回拨之前,请不要再调用另一个$().autocomplete
。 如果你有这样的级联,javascript引擎将在你从第一个回调之前运行它们。 因此它找不到它想要的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.