【发布时间】:2011-05-02 11:56:46
【问题描述】:
大家好……我又来了一个问题……
我在表单字段上使用 jquery 自动完成功能。有效!
问题是,然后我动态地在表单中添加另一行,但事实并非如此。是的,我一直将新字段的 id 切换为新字段。
原件 = 已通过 1 动态添加 =exampassed2,exampassed3 等等...
我已经添加了他们的 jQuery 等价物
$("#exampassed1").autocomplete({
source: "exams.php",
minLength: 2
});
$("#exampassed2").autocomplete({
source: "exams.php",
minLength: 2
});
等等……
我认为问题在于 jQuery 无法识别动态添加的元素,它只读取加载时存在的元素...
有什么方法可以让 jquery 处理程序读取这些新添加的元素??
我听说过 bind 和 live 功能,虽然我找不到实现这些功能的方法...
非常感谢这里的任何小/全部帮助......干杯!
我使用的 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>
任何指针也很感激!
再次感谢!
【问题讨论】:
-
对于最新版本的 jQuery,我会使用 .on() 代替 .live() 来动态添加 html 元素。
标签: php jquery html forms autocomplete