jQuery在.each循环中获取输入值 [英] jQuery get the input value in an .each loop

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

问题描述

我试图在复选框的每个循环中获取输入值,我无法弄清楚如何使其工作,值保持输出作为第一个复选框值。

I am trying to get the input value in an each loop of a checkbox, i cant figure out how to get this to work, the value keeps outputting as the first checkbox value.

$('.custemb, input[name=cb], input[class=multadd]').live("click", function() {

    $('input[class=multadd]:checked').each(function(index) {
        val = index + 2;
        valu = $('input[class=multadd]:checked').val();
        multiz = multiz + '&aid' + val + '=' + valu;
    });
});

问题是变量的输出值是每个循环的第一个复选框,而不是循环的当前复选框,我需要当前值。

the problem is the output of the variable valu is the first checkbox of the overall each loop, not the current checkbox of the loop, i need the current value.

任何想法?

推荐答案

您可以使用来访问循环中的当前元素:

You can use this to access the current element in the loop:

valu = $(this).val();

当前元素也作为参数发送给回调函数,因此你可以把它拿起来:

The current element is also sent as a parameter to the callback function, so you can pick it up:

.each(function(index, elem) {

然后使用参数:

valu = $(elem).val();

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

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