hasClassLike 介绍
hasClassLike allows the selection of elements based on pattern matching rather
than specific names. This allows, for example, the passing of parameters to
JavaScript via class names:
/* in js, such as in $(document).ready */ $("*") .hasClassLike("integer") /* filter some before using regexp */ .hasClassLike(/^integer(?:Min(-?\d+))?(?:Max(-?\d+))?$/,function(m) { var min = m[1]; var max = m[2]; // ... install validating event handlers on $(this) ... });
<!-- in HTML --> <input type="text" class="someOtherClass integerMin0"/> <input type="text" class="integerMin-100Max100 someOtherClass"/> <input type="text" class="someOtherClass integer yetAnotherClass"/>
There is an efficient simple substring match .hasClassLike(str) matched
against the entire className of the element (that is, the space-separated
list), useful for paring out unlikely elements. Then, a RegExp match with
.hasClassLike(rx) comes back with the elements bearing at least one class
matching a given pattern. Adding a callback function with .hasClassLike(rx,fn)
makes it easy to modify or filter the found elements based on the match, which
is passed to the callback function. If the callback returns false, the element
is not included in the output (like with .filter).
hasClassLike 官网
http://plugins.jquery.com/project/hasClassLike
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。