使用Jquery获取输入值

A.A*_*lov 3 arrays jquery

我有100个输入名称table[].我怎样才能将jQuery作为数组获得它们的价值?

我想尝试像$_POST['table']PHP一样.

我尝试了以下代码,但我希望将值作为数组...

$("input[name='table[]']").each(function(){document.write($(this).val());});
Run Code Online (Sandbox Code Playgroud)

rah*_*hul 5

var arrInputValues = new Array();
$("input[name='table\\[\\]']").each(function(){
     arrInputValues.push($(this).val()); 
     // you can also use this
     //arrInputValues.push(this.value);
});
Run Code Online (Sandbox Code Playgroud)

现在你的arrInputValues包含所有值.

你也可以使用

$("input[name='table[]']").each(function(){
Run Code Online (Sandbox Code Playgroud)

你可以看到一个有效的演示

您可以使用join()方法连接数组中的值.

arrInputValues.join(',');
Run Code Online (Sandbox Code Playgroud)

将数组元素作为字符串分隔,.