以下Jquery做了什么?

时间:2012-03-15 18:23:24

标签: jquery

ApplyClickableLinkToClass = function(selectedElements) {
    // Go through each of the passed in selections and try to apply a link to them
    $.each(selectedElements, function() {
        var linkElement = $("a:first:not(.do-not-apply-clickable-link)", $(this));
        var link = linkElement.attr("href");

        if (!IsNullEmptyOrUndefined(link)) {
            $(this).click(function(firstLink) {
                var divToLink = firstLink;
                return function() {
                    $(divToLink).unbind('click');
                    if (divToLink.attr("target") != "_blank") {
                        window.location = link;
                        return false;
                    }
                };
            } (linkElement));
        }
    });
}

如下所示:

ApplyClickableLinkToClass($j(".rc_blueBtn, .rc_whiteBtn:not(.More)"));

1 个答案:

答案 0 :(得分:0)

// loop over all selectedElements
$.each(selectedElements, function() {
    // find the first (a) that doesn't have the
    // class ('do-not-apply-clickable-link')
    // in the currently iterated element
    var linkElement = $("a:first:not(.do-not-apply-clickable-link)", $(this));

    // retrieve the matched (linkElement) href
    // attribute and store it in (link)
    var link = linkElement.attr("href");

    // bind click event to the currently iterated
    // element if the (link) was defined...
    if (!IsNullEmptyOrUndefined(link)) {
        $(this).click(function(firstLink) {
            var divToLink = firstLink;
            return function() {
                $(divToLink).unbind('click');
                if (divToLink.attr("target") != "_blank") {
                    window.location = link;
                    return false;
                }
            };
        } (linkElement));
    }
});