hasClassLike

授权协议 未知
开发语言
所属分类 jQuery 插件、 其他jQuery插件
软件类型 开源软件
地区 不详
投 递 者 皇甫智明
操作系统 未知
开源组织
适用人群 未知
 软件概览

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).