如何遍历jQuery元素 [英] How to iterate through jQuery elements

查看:63
本文介绍了如何遍历jQuery元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够看到jQuery找到的标记中的内容.下列内容为何无效?

I want to be able to see what's inside the tags that jQuery finds. How come the following doesn't work?

 $("div.UIImageBlock_Content.UIImageBlock_ICON_Content").each ( function() {
     alert(($this).html);
 });

什么是正确的方法?

推荐答案

  • $this => $(this)
  • .html => .html()
    • $this => $(this)
    • .html => .html()
    • 所以应该这样做:

      $("div.UIImageBlock_Content.UIImageBlock_ICON_Content").each ( function() {
           alert($(this).html());
       });
      

      请注意,html()函数仅使用innerHTML属性,因此它可以更加简单:

      Note that html() function just uses the innerHTML property, so it can be a lot simpler:

      $("div.UIImageBlock_Content.UIImageBlock_ICON_Content").each ( function() {
           alert(this.innerHTML);
       });
      

      这篇关于如何遍历jQuery元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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