开发者

jQuery: something is wrong with how this loop is being done

开发者 https://www.devze.com 2023-01-13 17:30 出处:网络
function appendRefToLinks(ref){ alert(\"hi\"); $j(\'a\').each(function(i){ alert(\'hello\'); $j(this).attr(\'href\',$j(this).attr(\'href\') + \"?ref=\" + $j.cookie.get(\"tb_ref\"));
function appendRefToLinks(ref){
    alert("hi");
        $j('a').each(function(i){
            alert('hello');
            $j(this).attr('href',$j(this).attr('href') + "?ref=" + $j.cookie.get("tb_ref"));
        }); 
}

I see the hi ale开发者_如何学运维rt, but I have to links on my page, and I never see hello.... what am I doing wrong?


You're probably calling the function before the page is parsed.

You need to wrap the code that calls it in $j(function() { ... }); so that it executes after the browser loads the page.


Did all the links rendered before you call the function?

You should use .click instead.

You can use .live so dynamic inserted links would also get the function.

0

精彩评论

暂无评论...
验证码 换一张
取 消