获取与数组具有相同类的所有输入的值

问题描述:

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

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());
}