:包含/开始 [英] :contain / start by

查看:109
本文介绍了:包含/开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在jQuery中有一个start by过滤器,类似于:包含一个字符串开始条件吗?

解决方案

不是我所知道的,但是您可以轻松地为jQuery实现自己的选择器:

  $。extend($。expr [ :'],{
startsWith:function(elem,match){
return(elem.textContent || elem.innerText ||).indexOf(match [3])== 0;
}
});

现在您可以像这样使用它:

< pre $ $(p:startsWith(Hello))。css(color,red)


Is there a "start by" filter in jQuery, something like :contain but with a string beginning condition ?

解决方案

Not that I know of, but you can easily implement your own selector for jQuery:

$.extend($.expr[':'], {
    startsWith: function(elem,match) {  
        return (elem.textContent || elem.innerText || "").indexOf(match[3]) == 0;
    }  
});

Now you can use it like this:

$("p:startsWith(Hello)").css("color","red")

这篇关于:包含/开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆