0

我正在开发一个相当简单的演示应用程序。三个输入下拉框slideDown()连续显示(这会change()在前一个下拉列表中触发),一个使用 AJAX 请求来确定下一个的值。

这在 Chrome 和 Firefox 中完美运行,但 IE(甚至 9)在第二个下拉列表中窒息 - 执行 AJAX 请求的那个。

因为代码胜于雄辩:

$('#specialty').change(function() {
    if ( $(this).val() !== "(please select an option)" ) {
        $.ajax({
                type: "GET",
                url: "getValidToppings.php",
                data: { location: $(this).parent().prev().children('select').val() }
        }).done(function(data) {
            var mytoppings, toppingsSelectBox;

            console.log('return values: ' + data);

            data = $.parseJSON(data);

            toppingsSelectBox = $('#toppings');
            toppingsSelectBox.empty();

            // we use the value from the select box as a key in the dict of toppings returned
            // from the AJAX call
            mytoppings = data[$('#specialty').val()];

            toppingsSelectBox.append('<option>(please select an option)</option>')

            for (i in mytoppings) {
                toppingsSelectBox.append("<option>"+mytoppings[i]+"</option>");
            }

            toppingsSelectBox.parent().slideDown('slow', 'linear');
        });
    }
});

您可以看到,当我更改此下拉列表(其中id="specialty")时,通过 AJAX(在 JSON 中)返回的值应该填充.toppings输入,然后显示它(使用slideDown())。但是,在 IE 中......没有骰子。

真正奇怪的是,如果我启动 IE 的开发工具并开始修改 Javascript(设置断点、使用控制台等),它就会开始按预期工作。即使我只打开开发工具,只要打开该窗口,它就会开始工作。有没有搞错?

这里发生了一些奇怪的事情。有任何想法吗?

4

1 回答 1

2

IE 不知道“控制台”是什么,除非您打开了开发工具。拿出来console.log,你应该很好。还要确保你没有遗漏任何分号,IE 往往不喜欢这样。

于 2012-06-12T20:34:34.883 回答