Removing event.preventDefault on click doesn't work

回眸只為那壹抹淺笑 提交于 2019-12-11 17:27:32

问题


I have this code which prevents default behavior on all elements:

$('body *').click(function(e){
e.stopPropagation();
e.preventDefault();
}); 

Now I would like to programmatically click a certain link in the page but first I have to remove the e.preventDefault(); so I used unbind:

$('a')[0].unbind('click');
$('a')[0].click();

This doesn't work for me. What am I doing wrong?


回答1:


You can't do

$('a')[0].unbind('click')

use .eq() to get the first element and then unbind

.eq(0).unbind('click')


来源:https://stackoverflow.com/questions/26239304/removing-event-preventdefault-on-click-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!