Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.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 使用jQuery each()函数遍历classname元素_Javascript_Jquery_Each - Fatal编程技术网

Javascript 使用jQuery each()函数遍历classname元素

Javascript 使用jQuery each()函数遍历classname元素,javascript,jquery,each,Javascript,Jquery,Each,我试图使用jQuery循环遍历具有相同类名的元素列表并提取它们的值 我有这个 function calculate() { // Fix jQuery conflicts jQuery.noConflict(); jQuery(document).ready(function(){ // Get all items with the calculate className var items = jQuery('.calcul

我试图使用jQuery循环遍历具有相同类名的元素列表并提取它们的值

我有这个

function calculate() {

    // Fix jQuery conflicts
    jQuery.noConflict();

    jQuery(document).ready(function(){    

        // Get all items with the calculate className
        var items = jQuery('.calculate');



    });    

}
我正在阅读each()函数,但是我不知道如何在这个实例中正确使用它

jQuery('.calculate').each(function() {
    var currentElement = $(this);

    var value = currentElement.val(); // if it is an input/select/textarea field
    // TODO: do something with the value
});
如果要在集合中获取其索引:

jQuery('.calculate').each(function(index, currentElement) {
    ...
});

参考:和功能。

非常感谢!!这可能是个愚蠢的问题,但“它的索引”是什么意思?它是集合中的索引。因此,例如,如果有3个元素与选择器匹配,则此变量将在每次迭代et上递增,并表示当前元素的索引。对于Rails和jquery Rails(3.1.0),一个更正是,参数首先是索引,然后是currentElemnt:
jquery('.calculate')。每个(函数(索引,currentElement)..
我可以使用的东西:?此答案与问题不一致:
$('.editable')
既没有在问题中声明,也没有在答案中声明
        $('.calculate').each(function(index, element) {
        $(this).text()
        });