获取与数组具有相同类的所有输入的值 [英] Get the values of all inputs with same class as an array

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

问题描述

我有一组输入,我想以数组形式或您建议的任何方式获取每个输入的值.我不太擅长数组.

I have a group of inputs and I want to get the value of each one in array form or in any way that you will suggest. I am not very good at arrays.

$(elemnt).each(function(index, element) {
    $('#spc-name').val($(".spocName").val());
    alert($(".spocName").val());
});

上面的代码行对我来说是正确的事情,但仅适用于单个输入,但是我使用class="spocName"具有多个输入,因此我想获取所有值,然后将每个值保存在DB表中的单独行中

the above line of code alert right thing for me but for a single input only but I have multiple inputs with class="spocName" so I want to get values of all and so that I could then save each in DB table in seperate rows.

推荐答案

如果所有输入共享同一类,请说"class1",那么您可以使用此选择所有此类输入

If all your inputs share the same class say "class1" then you can select all such inputs using this

var inputs = $(".class1");

然后,您可以根据需要对输入进行迭代.

Then you can iterate over the inputs any way you want.

for(var i = 0; i < inputs.length; i++){
    alert($(inputs[i]).val());
}

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

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