开发者

jquery: strange behavior with contextmenu

开发者 https://www.devze.com 2022-12-09 18:29 出处:网络
$(\"b\").bind(\"contextmenu\",function(e){ thiselementselected = e.target $(\"#add\").bind(\"click\",function(e){
$("b").bind("contextmenu",function(e){
thiselementselected = e.target

$("#add").bind("click",function(e){
thiselementselected.css("font-color", "red");
return false
});

$("#remove").bind("click",function(e){
thiselementselected.css("font-color", "");
return false
});

return false
});

when i click on a b> element and click 'add', it will make the font color red.

I do this for several b> elements.

then when i click on one of them and click remove, it will remove colors from ALL b> elements... its supposed to remove from on开发者_开发问答ly one given element b>

when i click on another b> and click 'add', now all previously selected b> elements will turn red !

i dont understand why this is happening....


try unbinding the click event on #add and #remove before you bind them to a new element. Otherwise you're just adding on to the event queue.

0

精彩评论

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