我正在尝试重定向网页上的链接,在这个简单的示例中,它只是通过简单的检查来设置要设置的 cookie。
不确定这是否是首先处理这种情况的正确方法,并且当“download_link”类有多个链接时我是否会遇到问题,但即使是现在,只有一个这样的链接,目标设置为未定义,看起来重定向器调用中的 $(this) 实际上指向整个 HTML 文档,而不仅仅是我要更改的元素...
    function redirect_link(e, destination) {
        if ($.cookie("contact_set") == "true") {
            window.location.href = destination;
        } else {
            alert("cookie not set");
        }
    }
    function redirector(destination) {
        alert("creating redirector to "+destination);
        return function(e) {redirect_link(e, destination)};
    }
    $(document).ready(function() {
        $('.download_link').click(redirector($(this).attr("href")));
        $('.download_link').attr("href", "#");
    });