时间:2021-07-01 10:21:17 帮助过:28人阅读
function yhCheckIsIncludingValue(element , pattern)
{
var bool = false;
var childrenNodes = element.childNodes;
if (childrenNodes.length == 0)
{
if (element.nodeValue != null)
{
if (pattern.exec(element.nodeValue) != null)
{
return true;
}
}
}
if (childrenNodes.length != 0)
{
for (var i = 0 ; i < childrenNodes.length ; i++)
{
if (bool = yhCheckIsIncludingValue(childrenNodes , pattern)) break;
}
}
return bool;
}
//在函数链应用这个函数
$.fn.contains = function(text)
{
var text = $.trim(text);
if (text == 'undefined') return this;
var pattern = new RegExp(text , 'i');
return this.filter(function(){
return yhCheckIsIncludingValue(this , pattern);
});
}
在IE浏览器上运行正常,不知道其他的浏览器会出现什么情况?