我试图使用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()
功能.