Javascript不会在Chrome上执行,但在FF和IE上运行正常

时间:2014-02-28 09:45:32

标签: javascript jquery google-chrome firefox

我有javascript代码填充我的页面上的选项卡,脚本在FF和IE上运行正常。但是,该脚本不会在Chrome上执行。我不确定它在Chrome浏览器上不会显示的代码有什么问题。 Chrome调试检查员对我找不到问题并没有多大帮助。

  

对于投注类型标签(链接属性不可点击且文字未显示)   HTML

<div id="tabs">
<ul id="betTypesTabs"></ul>
</div>

JS

function drawBetTypesTable(events, eventIndex) {

    // Clean the tabs
    $("#betTypesTabs").html('');

    // The required order: WIN, PLACE, EXACTA, QUINELLA, TRIFECTA, FIRST FOUR, RUNNING DOUBLE
    var orderedBetTypesIds = [1, 2, 105, 107, 106, 111, 108],
        eventId = events[eventIndex].id,
        categoryId = events[eventIndex].categoryId,
        betTypes = events[eventIndex].markets[0].betTypes,
        horseSelections = events[eventIndex].markets[0].selections,
        marketDescription = events[eventIndex].markets[0].marketDescription;

    // If event is the last one, Running Doubles cannot be shown
    if (eventIndex == events.length-1) orderedBetTypesIds.pop();

    $.each(orderedBetTypesIds, function (index, value) {

        var betTypeId = orderedBetTypesIds[index],
            i = null;

        $.each(betTypes, function (betIndex, betTypeValue) {
            if (betTypeValue.id == orderedBetTypesIds[index]) {
                i = betIndex;
                value = betTypeValue;
                return false;
            }
        });

        if (i != null) {

            // Draw the tab
            var a = document.createElement('a');
            a.className = eventId + "_betTypeId_" + betTypeId;
            a.text = value.name;

            var li = document.createElement('li');
            li.appendChild(a);
            document.getElementById("betTypesTabs").appendChild(li);

            // Draw the div with the table
            var div = document.createElement('div');
            div.id = eventId + "_betTypeId_" + betTypeId;

            var table = document.createElement('table');
            table.id = eventId + "_betType_" + betTypeId + "_table";
            table.cellspacing = "0";
            table.cellpadding = "0";
            table.width = "100%";
            table.className = "table_racing";

            document.getElementById("tabs").appendChild(div);
            document.getElementById(eventId + "_betTypeId_" + betTypeId).appendChild(table);

            // Bind click action to the tab link
            var currentA = $("ul#betTypesTabs").find('a[class="' + eventId + '_betTypeId_' + betTypeId + '"]');
            currentA.click(function(){

                // Making the tab active
                $("ul#betTypesTabs li").removeClass("active");
                $(this).parent().addClass("active");

                // Showing the correct div
                $("div#tabs div").hide();
                $("#" + eventId + "_betTypeId_" + betTypeId).show();

                // If it is a Running Double, highlight the next race number
                if (betTypeId == 108) {
                    (function(eventIndex){
                        var nextRaceNumber = events[parseInt(eventIndex)+1].raceNumber;
                        $("#raceNumber_" + nextRaceNumber).removeClass("gray");
                        $("#raceNumber_" + nextRaceNumber).addClass("orange");
                    })(eventIndex);
                }
            });

            var tableId = table.id;

            (function(betTypeId, eventId, categoryId, i, tableId, eventIndex) {
                // PLACE or WIN, WIN/PLACE bet types
                if (betTypeId == 1 || betTypeId == 2 || betTypeId == 3) {
                    drawPlaceBetTypeTable(eventId, categoryId, betTypes[i]);
                    drawSelections(betTypeId, tableId, horseSelections);
                }
                // EXACTA, QUINELLA, TRIFECTA, FIRST FOUR bet types
                else if (betTypeId == 105 || betTypeId == 107 || betTypeId == 106 || betTypeId == 111) {
                    drawExactaBetTypeTable(eventId, categoryId, betTypes[i]);
                    drawSelections(betTypeId, tableId, horseSelections);
                    drawHorseSelectionFooter(betTypeId, tableId);
                }
                // RUNNING DOUBLE
                else if (betTypeId == 108) {
                    drawRunningDoubleBetTypeTable(events, eventIndex, betTypes[i], 6);
                }

                // Append NB description if does not exist
                if (marketDescription != null && $("#" + table.id + '_notabene').length == 0) {
                    appendBetTableFooter(table, marketDescription);
                }
            })(betTypeId, eventId, categoryId, i, tableId, eventIndex);
        }
    });

    // Click on the 1st tab
    $("ul#betTypesTabs a")[0].click();
}
  

对于种族类型(链接是可点击的,但种族类型的文字不会显示在Chrome上)   HTML

<div id="raceNumbers" class="racenumbers">
</div>

JS

function drawAllRaceNumbers(events) {

    // Clean parent element
    document.getElementById("raceNumbers").innerHTML = '';

    // Draw a category name, which is same for all events
    var p = document.createElement("p");
    p.innerHTML = events[0].categoryName + ':';
    document.getElementById("raceNumbers").appendChild(p);

    for (var i in events) {
        var a = document.createElement('a'),
            eventNumber = events[i].raceNumber;

        // Racing specials
        if (eventNumber == null) {
            eventNumber = parseInt(i) + 1;
            a.text = eventNumber;
        }
        else a.text = raceAbbr + eventNumber;
        a.id = "raceNumber_" + eventNumber;
        a.className = "gray";
        document.getElementById("raceNumbers").appendChild(a);

        // Binding click event for the race number
        $("#raceNumber_" + eventNumber).unbind();
        (function(i, raceNumber) {
            $("#raceNumber_" + raceNumber).click(function() {
                drawRaceView(events, i);
            });
        })(i, eventNumber);
    }

    var div = document.createElement('div');
    div.className = "clear";
    document.getElementById("raceNumbers").appendChild(div);
}

编辑:删除指向我的开发环境的链接。

2 个答案:

答案 0 :(得分:1)

您需要更改使用'.text'设置元素内容的所有行。这不适用于chrome。您可以使用.innerHTML替换它,或者,正如您已经使用它,使用jQuery:$(a).text(data)

答案 1 :(得分:0)

您有错误:event.returnValue is deprecated. Please use the standard event.preventDefault() instead.