为什么这个Jquery函数似乎什么都不做

时间:2012-03-15 21:50:27

标签: 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));
    }
});

}

我认为它会在新窗口中打开目标并删除点击事件但在调用时什么都不做,有什么想法吗?

如下所示

    var clickable = function () {
    ApplyClickableLinkToClass($j(".rc_blueBtn, .rc_whiteBtn:not(.More)"));
    };
    setTimeout(clickable, 2000);

2 个答案:

答案 0 :(得分:0)

你有什么理由在函数调用中使用$ j()而不是简单的$()选择器吗?

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

答案 1 :(得分:0)

$(this).one("click", function() {

它很容易做你需要的只添加一次点击,然后自动删除。