【问题标题】:Why does the jQuery on this page work for Internet Explorer 8, but nothing else?为什么此页面上的 jQuery 对 Internet Explorer 8 有效,但没有别的?
【发布时间】:2010-06-18 10:40:32
【问题描述】:

我制作了一个使用 jQuery 的网页:http://benmccormack.com/demo/MichaelMassPsalm/Psalm16Mode5.html

当您将组合框中的选择从 Higher Key 更改为 Lower Key 时,所有音乐图像都应该将其源更改为代表低调签名的图像。这在 IE8 中运行良好,但在 Safari、Firefox 或 Chrome 中无法运行。

为什么不呢?


这是我正在使用的 jQuery 代码:

$(document).ready(function () {
    $("#musicKey").change(function (event) {
        if ($("#musicKey").val() * 1) {
            $("img[src*='Low'").each(function (index) {
                $(this).attr("src", $(this).attr("src").replace("Low", "High"));
            });
        }
        else {
            $("img[src*='High'").each(function (index) {
                $(this).attr("src", $(this).attr("src").replace("High", "Low"));
            });
        }
    });
});

【问题讨论】:

    标签: javascript jquery html cross-browser


    【解决方案1】:

    您的attribute-contains selectors 缺少右括号:

    $("img[src*='Low']")
    //and...
    $("img[src*='High']")
    

    目前,那个无效的选择器没有找到任何东西,所以没有什么可以执行的。

    【讨论】:

    • 所以 thaaaat 就是你用 IE 做的事情,你欺骗它去做你想做的事情。
    • @Babiker - 直到它吃掉你的猫、砸烂你的车、敲打你的女人并偷走你最好的朋友,或者那可能是 Lotus Notes,我再也不能直截了当......跨度>
    • 宾果游戏。就是这样。我猜IE8更宽容。另外,我更喜欢 IE8 在change 事件上的行为。一旦您选择了不同的选项,该事件就会触发。在其他浏览器上,您必须在事件触发之前移动焦点,这很烦人。
    • @Ben - 你可以在这里做.bind('click change', function... 而不是.change(function... 给定你正在做的操作:)
    猜你喜欢
    • 2010-12-31
    • 2011-08-13
    • 1970-01-01
    • 2010-12-23
    • 1970-01-01
    • 2012-11-26
    • 1970-01-01
    • 1970-01-01
    • 2015-05-13
    相关资源
    最近更新 更多