在另一个方法中覆盖preventDefault()

时间:2011-02-04 02:39:02

标签: javascript jquery

我有这个电话

<a onclick="facebookLogin();" class="facebook_btn_homepage" href="/signup">
<img src="/images/facebook_btn2.png?1280194712" alt="Facebook_btn2"></a>

    $('.facebook_btn_homepage').click(function(event){
        event.preventDefault();
    });

但是在函数facebookLogin()中我要覆盖

 function facebookLogin() {
   FB.login(function(response) {
 //i want to overwrite the preventDefault and go to another 
     //page because its trying to go to another url and the preventDefault 
     //is stopping the page from going to another url

2 个答案:

答案 0 :(得分:3)

您可以拨打preventDefault(),然后在需要时手动设置window.location

$('.facebook_btn_homepage').click(function(event){
    event.preventDefault();
    // do some stuff

    // then manually go to the next page
    window.location.href = this.href;
});

答案 1 :(得分:1)

为什么同时使用onclick属性和jQuery的click事件处理程序?

如果删除对onclick的{​​{1}}调用并将其放入jQuery单击处理程序,则可以在facebookLogin()函数中决定是否需要阻止默认操作(继续到facebookLogin())中指定的网址。

或者我错过了什么?

相关问题