为什么javascript / jquery在所有浏览器中执行但IE?

时间:2012-03-27 04:10:57

标签: javascript jquery

我希望一些新鲜的眼睛能看到我所缺少的东西。我有一个页面(在WordPress网站上),在Firefox,Chrome,Opera和Safari但不在IE中。为了查看它是否正在执行任何操作,我在document.ready函数的第一行放置了一个警报,它显示在除IE之外的所有浏览器上(在IE7和IE9上试过)。

这是document.ready函数。任何人都可以看到为什么这不会在IE中执行?

<!-- language: lang-js -->
$(document).ready(function () {
    alert('in .ready function');
    //$("input:text:visible:first").focus();
    $(window).scrollTop();
    // $(this).scrollTop(0);
    $("#u_phone").mask("(999) 999-9999");
    $('#fab_result').hide();
    $('#fab_header').hide();
    $('#optIn').hide();
    $('div.message').show();
    $('#mymap').show();
    $("#my_form").validate();
    if ($("#u_firstname").length > 0) {
        $("#u_firstname").rules("add", {
            required: true,
            minlength: 5,
            messages: {
                required: " This field is required "
            }
        });
    }
    if ($("#u_email").length > 0) {
        $("#u_email").rules("add", {
            required: true,
            email: true,
            messages: {
                required: " This field is required "
            }
        });
    }
    if ($("#u_phone").length > 0) {
        $("#u_phone").rules("add", {
            required: true,
            messages: {
                required: " This field is required "
            }
        });
    }
    if ($("#u_custom_20").length > 0) {
        $("#u_custom_20").rules("add", {
            required: true,
            minlength: 3,
            messages: {
                required: " This field is required "
            }
        });
    }
    var mapsterOpts = {
        fillOpacity: 0.5,
        render_highlight: {
            fillColor: '2aff00',
            stroke: true,
            strokeWidth: 2
        },
        render_select: {
            fillColor: 'ff000c',
            stroke: false
        },
        fadeInterval: 5000,
        isSelectable: false
    },
        mainOpts = $.extend({}, mapsterOpts, {
            mapKey: 'province',
            onClick: clickMain
        }),
        detailOpts = $.extend({}, mapsterOpts, {
            onClick: clickDetail
        });
    $('#canada-map').mapster(mainOpts);
});

1 个答案:

答案 0 :(得分:-1)

问题在这里:

使用var来声明变量,而不是使用逗号(,)代替(;)

改变这个:

var mapsterOpts = {
    fillOpacity: 0.5,
    render_highlight: {
        fillColor: '2aff00',
        stroke: true,
        strokeWidth: 2
    },
    render_select: {
        fillColor: 'ff000c',
        stroke: false
    },
    fadeInterval: 5000,
    isSelectable: false
},
    mainOpts = $.extend({}, mapsterOpts, {
        mapKey: 'province',
        onClick: clickMain
    }),
    detailOpts = $.extend({}, mapsterOpts, {
        onClick: clickDetail
    });
$('#canada-map').mapster(mainOpts);

    var mapsterOpts = {
        fillOpacity: 0.5,
        render_highlight: {
            fillColor: '2aff00',
            stroke: true,
            strokeWidth: 2
        },
        render_select: {
            fillColor: 'ff000c',
            stroke: false
        },
        fadeInterval: 5000,
        isSelectable: false
    };
    var mainOpts = $.extend({}, mapsterOpts, {
        mapKey: 'province',
        onClick: clickMain
    });
    var detailOpts = $.extend({}, mapsterOpts, {
        onClick: clickDetail
    });
    $('#canada-map').mapster(mainOpts);