为什么IE需要我点击两次 [英] why does IE need for me to click twice

查看:125
本文介绍了为什么IE需要我点击两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个jQuery

I have this jQuery

    $('.billing_info').click(function(e){
        e.preventDefault();
        if(($('.shipping_selection').length) > 0){
            if ($('.shipping_selection:checked').length == 0){
                $('.hide_error').show();
                $("html, body").animate({ scrollTop: $(".hide_error").offset().top }, "slow");
                $(".hide_error").effect("highlight", {}, 4000);
                return false;
            }else{
                $('.billing_info').unbind("click");
                $('.billing_info').click();
            }   
        }else{
            $('.billing_info').unbind("click");
            $('.billing_info').click();
        }
    });

除了IE之外,在所有浏览器中都很棒。我正在使用IE8并且用户需要单击按钮两次按钮才能接受点击事件,即使有一个单选按钮$('。shipping_selection')点击

which works awesome in all browsers except in IE. I'm using IE8 and the user needs to click the button twice for the button to accept the click event even if there is one radio button $('.shipping_selection') clicked

推荐答案

也许一点点重构会有所帮助。只在需要时阻止默认,否则让函数传递给默认的提交事件。

Perhaps a bit of refactoring would help. Only prevent default when you need to, otherwise let the function pass through to the default submit event.

$('.billing_info').click(function(e){
    if(($('.shipping_selection').length) > 0 && $('.shipping_selection:checked').length == 0){
            e.preventDefault();
            $('.hide_error').show();
            $("html, body").animate({ scrollTop: $(".hide_error").offset().top }, "slow");
            $(".hide_error").effect("highlight", {}, 4000);
            return false;
    }
});

这篇关于为什么IE需要我点击两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆