通过POST提交UL的最佳方法? [英] Best way to submit UL via POST?
问题描述
快速提问...
我有一个输入框,在输入该键时,会将值添加到无序列表中.我如何将这个无序列表传递给jquery帖子?我使用的是form.serialize,因此不必定义每个要发布的变量.
I have an input box that upon key enter, adds the value to an unordered list. How would I pass this unordered list to jquery post? I'm using the form.serialize, so I don't have to define each variable for posting.
例如,假设我输入了3个水果,它们被动态添加到表单内的无序列表中.
Example, let's say I entered 3 fruits and they get dynamically added to an unordered list inside the form.
水果:[在此处输入文字]
Fruit: [input text here]
- 苹果
- 香蕉
- 梨
- Apple
- Banana
- Pear
我正在考虑创建一个隐藏的文本字段,每当用户按下Enter键时,该字段就会填充新值.
I was thinking of creating a hidden text field that would populate with the new value everytime the user pressed enter.
还有其他想法吗?
推荐答案
<ul>
<li>Apple<input type='hidden' name='fruits[]' value='Apple'/></li>
<li>Pear<input type='hidden' name='fruits[]' value='Pear'/></li>
<li>Banana<input type='hidden' name='fruits[]' value='Banana'/></li>
</ul>
提交后,您将在$_POST
中获得一个名为fruits
的具有这些值的数组.
When submitted, you'll get an array in $_POST
named fruits
with those value.
这篇关于通过POST提交UL的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!