javascript – 使用jQuery each()函数循环遍历classname元素

我试图使用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) {
    ...
});

参考:.each().val()功能.

相关文章

jQuery表单验证提交:前台验证一(图文+视频)
jQuery表单验证提交:前台验证二(图文+视频)
jQuery如何实时监听获取input输入框的值
JQuery怎么判断元素是否存在
jQuery如何实现定时重定向
jquery如何获取复选框选中的值