代码之家  ›  专栏  ›  技术社区  ›  Nicholas Murray

jquery检索div数组的内容

  •  1
  • Nicholas Murray  · 技术社区  · 15 年前

    我在同一个类名的页面上有一个div集合。

    <div class="ProductName">Product Foo</div>
    <div class="ProductName">Product Bar</div>
    

    我希望能够检索、遍历和警告productname div的内容。

    目前,我可以检索和迭代,但我不能提醒个别内容。

    var ExistingProductNamesOnscreen = $.makeArray($(".ProductName"));
    $.each(ExistingProductNamesOnscreen, function (key, val) {
        alert(*ProductName contents*);
    });
    
    3 回复  |  直到 15 年前
        1
  •  4
  •   harpax    15 年前
    $(".ProductName").each(function(k, v) {
        alert($(v).text());
    });
    
        2
  •  1
  •   bang    15 年前
    $(".ProductName").each(function ()
    {
        alert($(this).text());
    });
    
        3
  •  0
  •   Adam Kiss    15 年前

    你试过吗?

    alert ($(this).text());
    

    alert ($(this).html());
    

    ?

    (第一个应该提醒 text 内容,而后者也有任何特别发现的标记 div )