【问题标题】:.find Inquiry about how to find <a> text.find 查询如何查找 <a> 文本
【发布时间】:2014-11-03 05:01:09
【问题描述】:

如何在标签下的页面上找到某些文本?

我试过了,但是没用:

var Link = "http://www.roblox.com/My/Groups.aspx?gid=34039"

function her() {
    $.get(Link, function (data) {
        if ($(data).find('No One!').length) {
            Post()
            LoL()
        }
    })
}
her()

【问题讨论】:

标签: javascript jquery post get


【解决方案1】:

如果你以 HTML 格式检索数据,那么你可以在下面做一行

// below example statement will Find all anchors that has No One! Text

var phraseToFind = "No One!";
//links that contain above phrase example.
var isAnyLinkWithPhraseFound = $(data).find('a:contains('+ phraseToFind +')').length > 0;

您的功能将发生如下变化:

function her() {
   var phrase = "No One!";
   $.get(Link, function (data) {
        if ($(data).find('a:contains('+ phrase +')')
                   .filter(function(){return $(this).text() === phrase }).length) {
        //this filter will give links with exact phrase
            Post()
            LoL()
        }
    })
}

【讨论】:

  • 我想要确切的短语“没有人!”要在页面上找到它的 HTML。
猜你喜欢
  • 1970-01-01
  • 2017-12-18
  • 1970-01-01
  • 1970-01-01
  • 2023-04-03
  • 2019-09-10
  • 1970-01-01
  • 2013-02-13
  • 1970-01-01
相关资源
最近更新 更多