Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用JS捕获多个值_Javascript_Jquery - Fatal编程技术网

Javascript 使用JS捕获多个值

Javascript 使用JS捕获多个值,javascript,jquery,Javascript,Jquery,但每次它都会给我第一个输入值 $('.customs').each(function() { alert($('.customs').val()); }); 替换 Required Alert output: Blue, Brand Output comes: Blue, Blue 与 替换 Required Alert output: Blue, Brand Output comes: Blue, Blue 与 在两个输入定义中对值与名称进行双重检查在两个输入定义中对值与

但每次它都会给我第一个输入值

$('.customs').each(function() {

    alert($('.customs').val());

});
替换

Required Alert output: Blue, Brand
Output comes: Blue, Blue 

替换

Required Alert output: Blue, Brand
Output comes: Blue, Blue 


在两个输入定义中对值与名称进行双重检查

在两个输入定义中对值与名称进行双重检查

您在每次迭代中都会评估选择器,我猜当对数组调用
val
时,它会选择第一个值

使用

甚至更好

$('.customs').each(function() {
    alert($(this).val());
});

因为这里不需要
val
提供的层。

您在每次迭代中都要评估选择器,我猜当对数组调用
val
时,它会选择第一个值

使用

甚至更好

$('.customs').each(function() {
    alert($(this).val());
});

因为这里不需要
val
提供的层。

因为您使用类作为选择器,所以您得到了一个集合。您可以通过将其放入数组或对其进行迭代来处理它

$('.customs').each(function() {
    alert(this.value);
});

由于使用类作为选择器,因此将获得一个集合。您可以通过将其放入数组或对其进行迭代来处理它

$('.customs').each(function() {
    alert(this.value);
});
$('.customs').each(function() {
   alert($(this).val());//use this to refer to the current object
});