0

我试图找出如何选择<span class="title">页面上的所有元素:

<div class="my-page">
    <span class="title">first</span>
    <span class="title">second</span>
    <span class="title">third</span>
    <span class="title">fourth</span>
    <span class="title">fifth</span>
</div>

存在于列表中(从 servlet 以 JSON 格式获取)并存储在某个变量中?

我试过类似的东西:

success : function(data, statusText, jqxhr) {
  var arr = data.selectedTitles;
    jQuery.each(data.favTools, function(i, v) {
      var title = v;
      jQuery('span.title:contains(title)').css("text-decoration", "underline");
    });
}
4

1 回答 1

10
$('span.title').filter(function() {
    return $(this).text().indexOf(title) != -1;
});
于 2012-05-25T15:28:35.763 回答