如何在jQuery中读取输入二维数组值? [英] How to read input two dimensional array value in jquery?

查看:957
本文介绍了如何在jQuery中读取输入二维数组值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,可以在html中添加许多联系人,输入是二维数组,这里是表单:

I have a form to add many contacts in html the input is two dimensional array here is the form:

<input class="form-control" type="text" name="account[0][name]" placeholder="Name"  autocomplete="off" />
<input class="form-control" type="text" name="account[0][email]" placeholder="Email"  autocomplete="off" />
<input class="form-control" type="text" name="account[0][mobile]" placeholder="Mobile"  autocomplete="off" />

<input class="form-control" type="text" name="account[1][name]" placeholder="Name"  autocomplete="off" />
<input class="form-control" type="text" name="account[1][email]" placeholder="Email"  autocomplete="off" />
<input class="form-control" type="text" name="account[1][mobile]" placeholder="Mobile"  autocomplete="off" />

我正在尝试使用jquery来获取值我尝试了以下操作,它返回了值,但是我想返回帐户名或帐户电子邮件或移动帐户的输入值

I am trying to get the value using jqueryI tried the following, it returns the value but i want to return an input value of account name or account email or account mobile

 $('input[name^="account"]').each(function() {
                console.log($(this).val());
        });

推荐答案

您可以使用开头,属性选择符结尾:

You can use the starts with and ends with attribute selectors:

$('[name^="account"][name$="[name]"]')

将选择名称以account开头和[name]结束的所有元素.

Would select all elements where the name starts with account and ends with [name].

这篇关于如何在jQuery中读取输入二维数组值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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