is contains this function, the book said this function is based on the content of elements to filter the selection of elements set, when I run the code always error, and later found that the function library does not have this function, so I wrote this function.
The code is as follows:
Copy Code code 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 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);
});
}
Running normally on IE browser, do not know what will happen to other browsers?