开发者

Jquery: function runs twice

Why does my jquery function runs twice on click ?

$("a").click(processAction);

function proce开发者_Python百科ssAction(e){
    var clicked = e.target;

//show apply button.

        $("#apply").live("click",function(e){
            e.stopPropagation();
            someFunction(clicked);
            alert("this the array " + mydata);
                clicked = "";
            }); 
}   

someFunction is running twice !


For every click on an a-element, you add a click handler to your #apply-element. If you click 3 times on an a-element, then click on #apply, three different instances of 'someFunction' will run.


.unbind("click").bind("click, somefunction) works beautifully.


If you are using .live() to attach the click event to that specific anchor, you don't have to attached another click event to the anchor using

$("a").click(processAction);

I'm not sure if it's intentional that you are putting the .live in the anchor click function, if it is not, you can pull out the .live() and seperate from the actual click function.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜