如何禁用jquery ui combobox?

LA_*_*LA_ 4 jquery-ui

我使用取自标准代码页,尝试禁用组合框:

$( "#cbCountry" ).combobox({ disabled: true });
Run Code Online (Sandbox Code Playgroud)

但它仍然启用.这有什么不对?

小智 15

易于修改组合框库使用:

$("#cbCountry").combobox('disable');
$("#cbCountry").combobox('enable');
Run Code Online (Sandbox Code Playgroud)

在你的combobox.js文件中添加:

  • _create中:function()添加局部变量"a"(之后var input,a...).
  • 更改input = $("<input>")input = this.input = $("<input>").
  • 更改a = $("<a>")a = this.a = $("<a>").
  • 插入后destroy:

    disable: function() {
        this.input.prop('disabled',true);
        this.input.autocomplete("disable");
        this.a.button("disable");
    },
    enable: function() {
        this.input.prop('disabled',false);
        this.input.autocomplete("enable");
        this.a.button("enable");
    }
    
    Run Code Online (Sandbox Code Playgroud)

    bfa*_*tto 6

    该代码用于初始化禁用的组合框.如果要禁用现有的组合框,请使用以下命令:

    $("#cbCountry").combobox("option", "disabled", true);
    
    Run Code Online (Sandbox Code Playgroud)

    UPDATE

    Combobox是一个单独的jQuery UI小部件,它似乎没有实现这些选项.我能够通过在窗口小部件中找到文本字段和按钮来禁用它,并禁用它们:

    $("#cbCountry").closest(".ui-widget").find("input, button" ).prop("disabled", true)
    
    Run Code Online (Sandbox Code Playgroud)


    Kar*_*N G 6

    我必须在我的Web应用程序中单击按钮时禁用组合框.感谢在此发表评论的人们.我能够想出如何在需要时禁用和启用组合框.代码如下.

    以下代码用于禁用组合框

    $("#MyComboboxId").parent().find("input.ui-autocomplete-input").autocomplete("option", "disabled", true).prop("disabled",true);
    $("#MyComboboxId").parent().find("a.ui-button").button("disable");
    
    Run Code Online (Sandbox Code Playgroud)

    上面的JavaScript代码查找ID的HTML元素,其余部分在上面的帖子中进行了解释.

    以下代码用于启用组合框

    $("#MyComboboxId").parent().find("input.ui-autocomplete-input").autocomplete("option", "disabled", false).prop("disabled",false);
    $("#MyComboboxId").parent().find("a.ui-button").button("enable");
    
    Run Code Online (Sandbox Code Playgroud)