PHP implements jQuery extension functions
- 2020-03-31 16:46:32
- OfStack
It's the contains function, which the book says filters the selected set of elements by their contents, and I kept reporting errors when I was running the code, and I wrote it myself because it wasn't in the library.
The code is as follows:
Internet explorer works fine. What happens to other browsers?
The code is as follows:
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;
}
//Apply this function to the chain of functions
$.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);
});
}
Internet explorer works fine. What happens to other browsers?