将jQuery函数应用于动态添加的项目 [英] Applying jQuery function to dynamically added item

查看:74
本文介绍了将jQuery函数应用于动态添加的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过jQuery append()函数添加新的文本框时,似乎jQuery无法将函数应用于该文本框;

When adding a new textbox via jQuery append() function it appears jQuery is unable to apply a function to that textbox;

            $("#ulList").append("<li><span class=\"ui-icon ui-icon-circle-close remove\"/><em class=\"selectedWord\">" + selectedWord + "</em><input class=\"acf acfb-input ac_input\" type=\"text\" id=\"" + name + "\" name=\"" + name + "\" value = '' /></li>");

            $("#" + name).autoCompletefb();

我试图应用于新添加的输入的函数是autoCompletefb()方法,但jQuery似乎无法找到新添加的对象.

The function I am attempting to apply to the newly added input is the autoCompletefb() method but it seems jQuery is unable to find the newly added object.

想法?

推荐答案

您要为输入提供name变量内容的ID,并选择一个具有formattedName变量内容ID的元素.两者有什么区别?如果它们相同,代码将起作用.

You're giving the input an ID of the contents of the name variable and selecting an element with an id of the contents of the formattedName variable. What is the difference between the two? The code would work if they are the same.

除此之外,在append()调用的结尾附近还有一个JS错误:

Besides that, you have a JS error near the end of the append() call:

value = \"\" />";+ "</li>");

可能希望它是

value='' /></li>");

这篇关于将jQuery函数应用于动态添加的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆