【问题标题】:jQuery Retrieve the contents of an array of divsjQuery 检索 div 数组的内容
【发布时间】:2010-02-09 11:04:29
【问题描述】:

我在一个页面上有一组具有相同类名的 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*);
});

【问题讨论】:

  • 感谢大家提供更优雅的解决方案!

标签: jquery arrays


【解决方案1】:
$(".ProductName").each(function(k, v) {
    alert($(v).text());
});

【讨论】:

    【解决方案2】:
    $(".ProductName").each(function ()
    {
        alert($(this).text());
    });
    

    【讨论】:

      【解决方案3】:

      你试过了吗

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

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

      ?

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-18
        • 2018-07-30
        • 1970-01-01
        • 2011-10-31
        • 1970-01-01
        相关资源
        最近更新 更多