开发者

jQuery doesn't work in IE but it works in Mozilla

Please help me my jQuery script doesn't work ie8 but works in FF please verify my code is there any error?

<div class="check_out_button" id="checkout" style="cursor:pointer"><?=translate('Check Out',$lang)?></div>

$(document).ready(function(){
    $('#checkout').click(function(){

    var amount = $('#dnt_amount').val();
    var flag = 0;

    if(amount == "")
    {
        $('#amounterr').css("display","block");;
        flag++;
    }

    if(flag ==开发者_StackOverflow社区 0)
    {
        var res = $("#form1").serialize();

        $.ajax({  
                    type: "POST",  
                    url: "<?=site_url('profile/checkout')?>",  
                    data: res,

                    success: function(msg)
                        {
                            $('#amount').val(amount);
                $('#amt').val(amount);
                $('#amounterr').css("display","none");
                $("#fundraiser").css("display","none");
                $("#fundraiser1").css("display","block");
                $("#about").css("display","none");
                        }  
                    }); 
            }           
        });
    });


Try this, there were some javascript errors like an unnecessary additional semicolon in line 8.

$(document).ready(function() {
    $('#checkout').click(function() {

        var amount = $('#dnt_amount').val();
        var flag = 0;
        if (amount === "") {
            $('#amounterr').css("display", "block");
            flag++;
        }
        if (flag === 0) {
            var res = $("#form1").serialize();

            $.ajax({
                type: "POST",
                url: "<?=site_url('profile/checkout')?>",
                data: res,

                success: function(msg) {
                    $('#amount').val(amount);
                    $('#amt').val(amount);
                    $('#amounterr').css("display", "none");
                    $("#fundraiser").css("display", "none");
                    $("#fundraiser1").css("display", "block");
                    $("#about").css("display", "none");
                }
            });
        }
    });
});


I would start by cleaning up that code a bit like the double ;; and in javascript you should always place the { at the end of the line.

//Bad
if()
{
}

//Good
if(){
}

You can read more about why here I'm not sure if that is the problem here but worth a try. If not we need more details.


Do you have a doctype? Do you tell the browser to use the most recent rendering engine? Which version of IE are you using? You only say that it doesn't work in IE but you don't say what do you mean by that. It's a wild guess that if it works in other browsers and not in IE then maybe your page gets rendered in quirks mode and you have some issues with event models. See this answer that I posted recently.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜