When running the jQuery code in the book today, I don't know whether it was a mistake in the book or a problem with my jQuery version. in the example above, a jQuery function does not exist, that is, the contains function, the book said that this function is based on the content of the elements to filter the selected element set, when I run the code is always an error, and later found that the function library does not have this "> <LINKhref =" http://www.ph
When running the jQuery code in the book today, I don't know whether it was a mistake in the book or a problem with my jQuery version. in the example above, a jQuery function does not exist, that is, the contains function, this function is used to filter the selected element set based on the element content. when I run the code, I always report an error. later I found that this function is not found in the function library, so I wrote this function myself.
The code is as follows:
[Php]
Function yhCheckIsIncludingValue (element, pattern)
{
Var bool = false;
Var childrenNodes = element. childNodes;
If (childrenNodes. length = 0)
{
If (element. nodeValue! = Null)
{
If (pattern.exe c (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 in the function chain
$. 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 );
});
}
[/Php]
It runs normally on IE. I don't know what will happen to other browsers?