jQuery 添加 &删除文本框
我有这组 html 代码,我想在单击“+”时附加另一个 input="text" 以增加文本框的数量,但我不确定 Parent().parent() 函数。有人可以帮忙吗?
这里是我的jquery和html提取,抱歉,由于缺少CSS,它们看起来有点混乱。
i have this set of html codes that i want to append another input="text" to increase the number of textbox as i click '+' but i am not sure of the parent().parent() function. Can anyone help?
here is my jquery and html extraction, sorry they do look abit messy because of absence of css.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为
.append()
会帮助您添加元素并.remove()
删除它们(请参阅 示例#1 和示例#2)。因此,
element.append(content);
将content
添加到element
HTML 的末尾(在其结束标记之前)。element.remove();
从任何地方删除element
,因此您应该将其用于“减号”按钮$("your_tr > td > label :last")
选择器(选择带有来自your_tr
的输入的最后一个标签)。I think
.append()
would help you adding elements and.remove()
removing 'em (see example #1 and example #2).So,
element.append(content);
addscontent
to the end ofelement
HTML (before its closing tag).element.remove();
removeselement
from wherever it was so you should use this for your 'minus' button with$("your_tr > td > label :last")
selector (selects last of labels with inputs fromyour_tr
).以下是一些修改...
HTML:
JavaScript:
附加注释
您的标签中没有文本。标签的想法是它可以通过描述需要在文本框中输入的内容来帮助用户。如果您不想要可见的标签,您可以选择使用 CSS 隐藏它 - 但您仍然应该有一个
输入任务名称
不想显示它?使用 CSS 隐藏它:
表格不应用于布局
尝试将 HTML 属性移至 CSS
希望这有帮助。
Here are a couple of amendments...
HTML:
JavaScript:
Additional Notes
You have no text within your label. The idea of the label is that it can aid users by describing what needs to be entered into the text box. You can choose to hide it with CSS if you don't want a visible label - but you should still have one
Enter a task name
Don't want to show it? Hide it with CSS:
Tables shouldn't be used for layout
Try to move your HTML attributes into CSS
Hope this helps.
您是否尝试过提供父级和 id 并通过它来引用它,您还可以使用克隆来直接复制输入标签,请记住在将克隆的 id 附加到父级之前更改克隆的 id,因为这也将是克隆的。
have you tried giving the parent and id and referring to it by that, you can also use clone to make a direct copy of an input tag, remember to change the id of the clone before you append it to the parent as that will also be cloned.