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