【问题标题】:Why does this select menu fail in new version combo of jQuery and JQM?为什么这个选择菜单在 jQuery 和 JQM 的新版本组合中失败?
【发布时间】:2014-12-18 22:30:13
【问题描述】:

想扩展此代码,但注意到它无法在较新版本的 jQuery 和 JQM 中限制选择(按计数)。

Here is a fiddle 表明它适用于 jQuery 1.8.3 和 JQM 1.2.0。

jQuery(减去 Select 本身)代码在这里:

$(document).on("pageinit", function () {
    $("#select").on("change", function () {
        var selected = $("option:selected", this).length;
        if (selected == 4) {
            $("option:not(:selected)", this).prop("disabled", true);
            $(this).selectmenu("refresh");
        }
        if (selected < 4) {
            $("option:disabled", this).prop("disabled", false);
            $(this).selectmenu("refresh");
        }
         arr = new Array();
                    $(this).find("option:selected").each(function(index, item) {
                        arr.push($(item).val());
                        console.log(arr);
                    });
    });
});

您可以通过切换到 jQuery 1.11.0 和 JQM 1.4.4 来模拟小提琴中的故障。

然后,选择第 5 个应该被阻止但被允许的选项。

我遗漏了什么会导致新版本失败?

PS:任何指向使用 $.ajax GET 填充选择框的最佳方法的指针都值得赞赏,因为这将是我的下一步。我正在使用 POST 来保存选择,但想在用户需要更新时向他们展示他们已经保存的内容。

【问题讨论】:

    标签: javascript jquery ajax jquery-mobile


    【解决方案1】:

    您必须将true 作为第二个参数传递给selectmenu 函数,以强制它在禁用该选项后刷新菜单。 Check this Fiddle

    $(this).selectmenu("refresh", true);
    

    【讨论】:

    • 是的,这就行了!我怀疑该要求可能隐藏在各个版本之间的发行说明中。谢谢!
    猜你喜欢
    • 2013-11-22
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 2011-01-18
    • 2021-02-22
    • 2011-08-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多