【问题标题】:jquery selector start with content [duplicate]jquery选择器以内容开头[重复]
【发布时间】:2012-11-18 21:51:36
【问题描述】:

可能重复:
Jquery select all elements with an innerHTML that starts with a string?

我的代码:

<a href="#">Prefix today is monday</a>
<a href="#">Prefix today is wednesday</a>
<a href="#">other links</a>

是否有一个jquery选择器可以通过以“前缀”开头的内容来选择元素?

我知道有一个这样的包含选择器:

$("a:contains('Prefix')")

但它是“包含”,是否有“StartWith”内容选择器?

【问题讨论】:

标签: jquery


【解决方案1】:
$("a:contains('Prefix')").filter(function(){
    return this.innerHTML.indexOf('Prefix') == 0;
})

如果您不希望 HTML 干扰,您也可以检查文本:

$("a:contains('Prefix')").filter(function(){
    return $(this).text().indexOf('Prefix') == 0;
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-27
    • 1970-01-01
    • 1970-01-01
    • 2013-08-24
    相关资源
    最近更新 更多