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

前端之家收集整理的这篇文章主要介绍了javascript – 使用jQuery each()函数循环遍历classname元素前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图使用jQuery循环遍历具有相同类名和元素的元素列表.提取他们的价值观.

我有这个..

  1. function calculate() {
  2.  
  3. // Fix jQuery conflicts
  4. jQuery.noConflict();
  5.  
  6. jQuery(document).ready(function(){
  7.  
  8. // Get all items with the calculate className
  9. var items = jQuery('.calculate');
  10.  
  11.  
  12.  
  13. });
  14.  
  15. }

我正在阅读each()函数,虽然很困惑,如何在这个实例中正确使用它.

解决方法

  1. jQuery('.calculate').each(function() {
  2. var currentElement = $(this);
  3.  
  4. var value = currentElement.val(); // if it is an input/select/textarea field
  5. // TODO: do something with the value
  6. });

并且如果您想要在集合中获取其索引:

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

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

猜你在找的jQuery相关文章