获取的使用jQuery的输入值 [英] Get value of inputs with Jquery

查看:120
本文介绍了获取的使用jQuery的输入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为100的输入表[] 。我怎样才能得到他们与jQuery值,作为数组?

我试图做类似 $ _ POST ['表'] 在PHP。

我尝试以下code,但我想要的值作为一个数组...

  $(输入[名称='表[]'])每个(函数(){的document.write($(本).VAL());}) ;


解决方案

  VAR arrInputValues​​ =新的Array();
$(输入[名称='表\\\\ [\\\\]'])。每个(函数(){
     arrInputValues​​.push($(本).VAL());
     //你也可以使用此
     //arrInputValues​​.push(this.value);
});

现在您arrInputValues​​包含了所有的值。

您也可以使用

  $(输入[名称='表[]'])。每个(函数(){

您可以看到一个 工作演示

您可以使用join()方法加盟值数组中

  arrInputValues​​.join('');

将加入数组元素由分隔字符串。

I have 100 inputs with the name table[]. How can I get their value with jQuery, as an array?

I am trying to do something like $_POST['table'] in PHP.

I tried the following code, but I want the values as an array...

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

解决方案

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

Now your arrInputValues contains all the value.

You can also use

$("input[name='table[]']").each(function(){

You can see a working demo

You can use join() method to join the values in the array.

arrInputValues.join(',');

will join the array elements as a string separated by ,.

这篇关于获取的使用jQuery的输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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