如何获得使用jQuery,多℃的阵列;输入>具有相同名称的 [英] How to get an Array with jQuery, multiple <input> with the same name

查看:85
本文介绍了如何获得使用jQuery,多℃的阵列;输入>具有相同名称的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格,用户可以使用jQuery添加输入字段。

I have a form where users can add input fields with jQuery.

<input type="text" id="task" name="task[]" />

在提交表格后,我得到一个数组在PHP。

After submitting the form I get an array in PHP.

我想用 $阿贾克斯()来处理这个问题,但我不知道如何把我的&LT;输入&GT; s到jQuery中的数组。

I want to handle this with the $.ajax() but I have no idea how to turn my <input>s to an array in jQuery.

先谢谢了。

推荐答案

使用地图

var values = $("input[id='task']")
              .map(function(){return $(this).val();}).get();

如果您更改或删除ID(这应该是唯一的),你也可以使用选择 $(输入[名称='任务\\\\ [\\\\]'])

If you change or remove the id (which should be unique), you may also use the selector $("input[name='task\\[\\]']")

的例子: http://jsbin.com/ixeze3

这篇关于如何获得使用jQuery,多℃的阵列;输入&GT;具有相同名称的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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